span8
span4
本文将向您展示如何使用FME Server来驱动一个REST API的操作。在这里,我们来看看常见的情景与API网关集成FME Server,然后经过一个更具体的例子。
Web服务允许您与服务器或使用HTTP标准的简单网络网络上的其他节点进行交互。其余的概念本身不是一个标准,而是一系列促进简单,易于使用的Web API的指导方针。
该指南包括使用:
大多数的REST API的接受和JSON或XML格式的数据的具体响应变种。在过去的几年里,我们已经看到XML对JSON运动离开,因为它是在Web应用程序更容易支持。内置FME服务器上的Web服务可以支持XML或JSON,但我们会在本教程中使用JSON。
它正变得越来越普遍,设计应用程序和系统服务的集合,而不是铁板一块。根据实现的规模,你可能会听到这样的面向服务的架构(SOA)或微服务架构方面。虽然有很多细节值得商榷,其核心思想是,应该有一个系统的组件之间的明确定义的边界,他们应该利用良好定义的协议进行通信。这导致服务的集合在执行更小的任务,而不是满足所有要求的单一应用程序。所有这些服务都可以使用不同的技术来实现,并有可能由不同的团队进行管理。
但是,往往还是需要提供综合来自不同服务的数据和操作的统一接口(API)。这是用做API gateway- 本质上是提供了统一的接口另一个服务,并在后台所有不同的服务进行通信。
从这个概念借用,我们将使用FME Server来提供基于工作区服务。然后,我们将建立使用AWS API网关一个REST API,并将其链接到FME Server的Web服务。在这个系统中,其他工作区,FME Server实例,或完全不同的产品,甚至提供网络服务的未来迭代,可以添加额外的功能。亚搏在线娱乐平台
我们选择使用AWS API网关在本教程中,因为我们已经使用FME云和其他解决方案AWS。然而,还有其他几个选项,克罗ud based and self-hosted (on-premises).
If you want to use a different cloud service provider, you could look into solutions such asApigee Edgeor3scale。If you're looking for an on-premises solution, you can consider products such asNginx API GatewayorKong。(This is by no means an exhaustive list).
In this tutorial, a city is starting to roll out an API for public and internal use.The Parks Board is the first department to build a web service, but other departments will be doing the same soon.The Parks Board has decided to use FME Server to implement the service, but this will actually be invisible to users of the API.Other departments may choose to use FME Server, other software providing GIS web services, or simply host some static files if their data is fairly simple and not updated frequently.This will all integrate neatly into the same API.
用户 need to be able to carry out the following using the parks service:
The operations should properly be restricted to specific users.Querying the service is available to members of the public, but only internal users are permitted to modify the data.
The operations should be accessible through a RESTful web service, which can be expanded in the future to include services from other municipal departments.
Each of the required actions on a resource needs to be mapped to an HTTP action on a URL endpoint in the API:
行动 | 端点 |
检索所有公园 | GET /公园 |
查询公园数据集 | GET /公园?key = value的 |
检索特定公园 | GET /园区/
|
添加一个新的公园 | POST /公园 |
更新公园 | PUT /园区/
|
删除公园 | 删除/园区/
|
We’ll be using FME Server to build the parks web service, since FME makes it easy to properly format the data from the Parks Board internal database.However, the job-based workflow of FME Server isn’t ideally suited to building a REST API.Instead, we are going to use a specialized API Gateway.Specifically, we’ll be using aptly-named Amazon AWS API Gateway.
Since we are distributing GIS data through the web, a natural choice for request and response types is GeoJSON.
It’s good practice to first implement a simple example end-to-end to demonstrate that your systems are communicating properly.In this case, we will implement the /parks query, which just involves a translation from MapInfo TAB to GeoJSON.This will require configuring data streaming, security, and the API Gateway.
The workspace is very simple for this first API call.We’ll just be using the Parks.tab file from the FME sample data package.For your convenience, there is a workspace template available.
Save the workspace asgetAllParksGeoJSON.fmw
Next, we publish the workspace to FME Server.In this tutorial, we’ll be publishing to an FME Cloud instance, since it can be easily accessed from AWS API Gateway.
Now, let’s create an API user.Note that this user should have all privileges required to make calls to the API.The actual authorization of external vs.internal users is done at the gateway level.
Steps to set up the API user:
Now, let’s generate a token for the user:
We need to get the URL to run the workspace via the Data Streaming service:
Log in to your AWS Management Console, and go to网络和内容交付> API网关。Now, we’ll create a new API, and add a method to it.
选择得到作为动作。
Now that we’ve created an API with one resource and one method, we can deploy it and try it out.
Note that future methods you create can also use the token you specified in the stage variable, so if the token changes, you will be able to just set at the stage level.You could do something similar for the server URL if you have separate development and production FME Servers.
Using this example, we can implement further API calls using FME Server workspaces.Some ideas to work with:
©2020安全亚搏在线软件公司|法律