API Creation with the FlowEngine
This option allows you to create APIs with the power of FlowEngine functions.
To create an API from the FlowEngine, follow these steps:
- Select the option "My Digital Flows" from the Development menu:
- Select the domain and click the "View it" button:
- Look for the "onesaitplatform API" type nodes. You will see there are three different nodes:
- Drag a "onesaitplatform api rest" type node and double-click on it. The node's properties will appear and you can fill in the fields:
- Name: The name you will give to the API.
- Description: A detailed description for the API.
- Categories: Select one category in the drop-down list that the API can belong to.
- Is Public: This check box specifies whether the API will be public or not.
- Drag a "onesaitplatform api rest operation" type node, link it to the previous node, and double-click on it to edit its properties. Fill in the following fields:
- Method: Method of the REST API operation (GET | PUT | POST | DELETE).
- URL: Operation path.
- Name: Name you will give to the operation.
- Description: Detailed description of the operation.
- Query Params: JSON where each of the query params are declared, with their types.
If you want to define path/query params, you can do it like this:- Path params: They are defined in the path, with the ':' character preceding their names, for instance:
and they can be recovered in the following node through msg.req.params.<parameter-name>: - Query params: They are explicitly defined with a json specifying the parameter's name and type:Â
and they can be recovered in the following node through msg.req.query.<parameter-name>:
- Path params: They are defined in the path, with the ':' character preceding their names, for instance:
- For each operation, you must implement any needed logic. In this example, you can use "Function" nodes that will do the operations you deem neccessary.
- Once the needed logic is implemented, you must close each operation's flow with a response ("onesaitplatform api rest operation response" node). This node is in charge of returning both the response message body in "msg.payload" and a status code. This code will be 200 by default, but there are two ways to change it:
- writing the return code directly in the node,
- or making a previous node pass it in msg.statusCode
- writing the return code directly in the node,
- Once you are happy with your operations on the API, click on the "Deploy" button for the changes to be saved in the platform:
- As with the other APIs that can be created in the platform, the definition is available through the API Manager. From there, you can test it from swagger.