Making an external service available as a Flow Engine API
Introduction
This tutorial shows an example in which an external service is made available by creating a REST API from the Flow Engine.
Before starting
Before starting, you must bear in mind several elements of the petition that must be processed.
- Message Headers: Headers must be processed, for example, in the case of an OAuth token change. It is very important to remove the X-OP-APIKey header so as not to expose the personal token to external services (msg.req.headers).
- Params: Params must be set when creating the API endpoint, and then processed correctly.
- Body: The body must be obtained and sent in the correct way.
Nodes
For these types of flows, mostly the following nodes will be used:
Nodes for creating the REST API:
A more in-depth explanation of these nodes can be found in the tutorial: API Creation with the Flowengine.
Request to the external service nodes:
The following node is used to make HTTP requests to an external service. It is usually preceded by a function that processes the message received at the API endpoint, and it formats that message to make the request to the external service.
Creating the flow
In this tutorial, we are going to serve the service that gives us information about the people in space at the current moment (Open Notify (people in space and ISS position)).
Firstly, create a domain. In this case, we are using the analytics user, so the domain will be analyticsDomain.
When viewing the domain, you can edit the flow, where the REST API and the endpoints of the two services to be exposed are both created.
The basic scheme of an API is as follows, where the functions and calls to external endpoints will then be inserted.
When deployed, this generates an API with two endpoints (swagger view):
Now, a function is introduced to eliminate headers (headers that contain X-OP-APIKey and are not necessary for the external endpoint, and are also a security threat as they can expose the token to the outside).
Once deployed, the REST APIs are ready for use. An example of use is shown:
And the service response: