We will also see how Mule flow responds in case of Success and Validation scenarios.
RAML stands for RESTful API Modeling Language
RAML (Rest API Modeling Language) is based on YAML format, which is used to design REST APIs. RAML provides various features, including standardization, re-usability, easy readability, and much more. RAML provides a structure to the API which is useful for developers to start development process and it also helps clients to understands the request and response structure outcomes before hand.What RAML contains?
- Endpoint URL with its Query parameters and URI parameters,
- HTTP methods to which API is listening to (GET, POST, PUT, DELETE),
- Request and response schema and sample message,
- HTTP response code that an API will return (eg: 200, 400, 404, 415, 500).
Lets jump into code build:
Step 1: Download a sample RAML file link
Step 2: Create Mule project: From AnypointStudio
GoTo File--> New --> Mule Project
- Provide Project Name
- Select Runtime
- Import RAML file by specifying file location or URL
- Click finish button
Step 3: Building and Running Mule Project
Right click on the project --> Run As --> Mule Application
Step 4: Test your deployed App through API Console
Flow execution sequence in Success Scenario
In API console, When we click on "GET"
- Request will be sent to HTTP listener endpoint.
- HTTP listener takes the request and forwards to APIKit router
- APIKit validates the incoming requests and passes it to designated flow.
- Here it is passing to "get:\apikit-login:apikit-raml-flow-Mule4-config" flow
- Request is processed and gives a 200 OK response.
Step 6: Check Error Scenario
On Api Console, When we execute DELETE operation.
- Enter incorrect value in Delete Id.
- Request will receive to HTTP endpoint and forwards to APIKit router.
- APIKit router validates the incoming request.
- On validation failed APIKit throws an error and which is caught by error handler.
- Error handler passes the flow execution to APIKIT:BAD_REQUEST scope and gives response with status code 400
Below are some error codes and their meanings which we normally uses in our development.
Please find sample Mule project in Github raml-apikit-flow-mule4
Next article we will see how to write MUnit test cases for these APIKit flows - Part 1
No comments:
Post a Comment