Publish API
You can easily create an API from your Flowfactory model and publish the API to be accessed by third-party applications or other Flowfactory applications
Let us guide you through the steps to publish an API from Flowfactory.
1. Create and organize your APIs
Click Integrations → Publish API
You organize your APIs under Areas, start by adding a new Area and name it Products and give it a suiting description.
This will create a new Area where you can add your API resources (endpoints). Double click your newly created area to start creating your endpoints.
2. Create and API endpoint
Click add to create a new endpoint with the following parameters.
Resource - the name of the resource, this will correspond to URL endpoint resource name (e.g. https://www.api.com/api/product)
HTTPMethod - The type of verb for the API, currently supported verbs are GET and POST. To delete or update posts you can simply use post and create an corresponding workflow to handle these operations
Workflow To Run - This defines the workflow that will be executed when an external application calls your API. The parameters for the API are defined from the parameters of the Workflow. See section Workflows for Publish API
Routing Id - You can select a property on your in-parameter for the API that will be used as a in-path routing id. As an example if we select Id as Routing Id your API will expose an endpoint with Id as a resource path, https://www.api.com/api/product/{id}
Version - You need to define a version of your API, see section Version management.
Is Published - When this flag is set your API is available externally.
3. Workflows for Publish API
When your API is called from an external application a workflow is executed.
Below is an example of a workflow that uses a parameter entity to define in-parameters for your API and a Return Value that defines the result entity of the API
API Parameter
When an external application calls your API it can send parameters with the request. Below we have defined a parameter entity called API: Get Product Parameter.
This entity contains a Article Number field and a Product Name field. The external application can now add parameters in the body like this
{
“ArticleNumber” : “G1003”,
}
You can then use these parameters in the workflow to perform filtering or other logic on your query for products.
The parameters are set in your workflow as Root Entity Type
API Result
In the same way as with parameters you also define an Entity that holds the result that should be returned to the calling application. In this case we want to return a collection of Product entities which will be returned as a JSON-object with a collection of products.
Result parameters are defined in your workflow as Return Values.
4. Version management
To handle changes in your APIs you need to define a version. This makes it easy to later add new version of your API but still keep your API backwards compatible with previous versions.
To add a new version simply go to Manage Versions and click Add. You now set a name and a date for your version.
Consume API
With Flowfactory you can easily consume external APIs using Low-Code. To get started click Integrations-> Consume API.
1. Setup Consume API
From here you can add new endpoints and configure calls to API, start by clicking add
Name - Name of your API
API Reference URL - This is the first part of the endpoint URL. From this reference URL we will later add resources to access specific parts of the external API
After you have created a new Consume API you can add headers if necessary. These are global headers that will be applied to all call of this API. Example of global headers can be API-keys to grant access to an API.
When your base Consume API is setup you can start adding specific resources.
Name - The name of the resource, this will be used when configuring activities to call an external API
Url - This is the second part of the URL and will be appended to the ReferenceURL defined in the base Consume API
HTTPMethod - This is the verb of the resource, currently we support POST and GET
Parameter Entity Type - This is the parameter entity sent to the external API
Response Entity Type - This is the response entity that is used to collect the result from the external API call
Content Type - Use this property to set what kind of content the external API expects, supported Content Types are json, text and www-x-urlencoded.
2. Consume API from an activity
When you have created an Consume API you can access and make the call from any workflow in your application. Add a new Call REST API Method Activity to your workflow. Configuring the activity is really simple, you just choose the Consume API you want to use in REST API and then pick the API Method that should be called.
After the activity has been added you can bind parameters to the activity like any other activity in Flowfactory.
3. General Parameter Mapping
When creating APIs in Flowfactory we use naming convention to map properties from Flowfactory models to external model (JSON). We are going to show an example of how our mapping works.
For the product API we have the following properties
The column Name is what we will map to the consumer/publishing external application.
The external API needs to provide a JSON structure that corresponds to these names. In the above example the JSON would be.
{ "ArticleNumber" : "G001", "Description" : "Description of product G001", "Name" : "Product G" "Price" : "12499.50" }
Complex data contracts
APIs with more complex data contracts are handled in the same way with the name of the property as the convention for mapping properties.
In the following example we have a data structure that corresponds to the following JSON
{ "Shortname" : "API Demo", "Description" : "Amazing demo", "ContactContract" : { "Email": "customer.email@flowfactory.com", "Phone": "012-3456789" }, "Reminders" : [ { "AlarmSound" : "Loud", "When" : "2021-06-25" }, { "AlarmSound" : "Discrete", "When" : "2021-06-26" } ] }
This will be mapped to Flowfactory Entities like shown below.
{ "Shortname" : "API Demo", "Description" : "Amazing demo", "ContactContract" - (Mapped to Entity with name ContactContract) "Reminders" - (Mapped to Collection of EntityType with name Reminder) }
"ContactContract" : { "Email": "customer.email@flowfactory.com", "Phone": "012-3456789" },
{ "AlarmSound" : "Loud", "When" : "2021-06-25" }
Comments
0 comments
Please sign in to leave a comment.