Adding a Front-End API for API Customization
Using this Backend-for-Frontend pattern, you can easily derive multiple services from a back-end application without any code effort.
For example, a shop hosts a service that sells all sorts of things. In order to maximize its marketing, the shop decides to create APIs specific to a certain type of items such as books or movies. Instead of creating multiple integration applications which are very costly, the shop decides to build specific APIs for each of those items that in the end call the same integration application. Each Microflow application exposes a different front-end API and transforms the requests of all sorts into the generic format to send to the back-end integration application.
The following tutorial shows how to create a Cat service by modifying one API operation from the existing Petstore service:
- On the Apps page, click the default application,
On the Application Details page, click the Implementation tab and then click Edit.
The Microflow page is displayed. A set of stages are added to the sample.
In the left Operations section, click Frontend API > Import to import the front-end API specification.
You can model your Cat service in TIBCO® Cloud Integration - API Modeler based on the existing Petstore API specification, and then export the Cat API specification in the Swagger JSON format. This Cat API specification is used as the front-end specification in this tutorial.
Swagger Specification Reference is a copy of the Cat Swagger specification.
Note: The API specification must be a Swagger specification.
- Click Continue when you are prompted to confirm the importing.
Click the operation that you want to link a front-end operation to, POST/pet is selected in this tutorial; then move the cursor to the REQUEST button at the top of the flow.
Click the unlinked list and then select the
/catoperation as the front-end operation.
A list of POST operations are displayed, including the one
/catin the new Cat API specification that you just imported.
Note: If you do not choose another operation to replace the original one, it indicates that you still want to use the original back-end operation as the front-end operation. Therefore, make sure the original back-end operation is also added in your new front-end specification.
Click Push updates to deploy the Microflow application.
The application icon turns to green when the application is successfully pushed and run.
Click the Endpoint link of the deployed sample Microflow application and then click View API to test the Microflow application.
On the API Tester page, click the Cat resource and then post a cat using the default model schema. The front-end API operations are shown up for testing, rather than the back-end API operations.
Click Try it out to send the request.
From the example you can see that your customer can use a new operation to access the service by replacing the original operation with a new front-end operation. Microflow translates the request to the front-end operation into a request in the format of the back-end API and sends it to the back-end service.
For each operations in the front-end specification, you either make sure they are explicitly linked to a back-end operation, or they exist the same way in the back-end specification; otherwise sending request to these front-end operation will fail.
After linking the front-end API operation to the corresponding back-end API operation, you can use the Show relationships function to view the mapping between the API operations.
On the Microflow editing page, click Frontend API > Show relationships in the Operations section, the API operation mapping is displayed along with the configured stages of the front-end API operation: