The APIkit Router element allows you to define an API. It helps developers generate whole code from the API specification (RAML file) itself. But apart from generating flows from the API specification, it also helps in routing the incoming requests to specific flows of the API.
The APIkit router is a key message processor that validates requests against the RAML definition, enriches messages, for example by adding default values to the messages, and routes requests to a flow. “Bad request” is returned if the request is invalid, for example, and “Not implemented” is returned if the RAML resource that you request is not associated with a flow.
Steps to Use APIkit Router
1. Create an API specification (RAML). You can create an API specification from the Design Center(Anypoint Platform) or you can create it manually in any of the text editors.
#%RAML 1.0 title: TEST baseUri: placeholder.example.com description: API kit router test mediaType: - application/json version: "1" /test: get: displayName: Get test description: API kit get test post: displayName: Post test description: API kit post test put: displayName: Put test description: API kit put test delete: displayName: Delete test description: API kit delete test
Create a new project in Mule.
Import or copy the API specification in “src/main/resources/api” folder.
Generate flows from the API specification file.
- Right-click API Specification.
- Select Mule.
- Select Generate Flows from Local REST API.
Flows from the API specification will be generated, which you can check once the above step is done.
Configure HTTP listener.
Configure all flows unique to each HTTP method and URI. In this demo, I have configured the set payload for each unique HTTP method and URI combination.
API Tested in POSTMAN
If you like my post please follow me to read my latest post on programming and technology.