Creating Mule 4 Project with RAML
In this Mule tutorial we will learn how to Create Mule 4 project with RAML and a detailed walk-through on how the Mule flow works in case of a success or error scenario:
Mule ESB – What is RAML and why it’s used
RAML stands for RESTful API Modeling Language and is similar to WSDL. A RAML provides a structure to the API which is useful for developers to start there development process and also helps client who is invoking the API to know before hand what the API does.
A RAML contains:
How to create Mule project with RAML:
1. Download a sample RAML file:
To create a Mule project with RAML you can download RAML from here.
2. Creating a Mule Project:
In Anypoint Studio create a new Mule Project. File > New > Mule Project
Next, Give the Mule Project a name and select Mule runtime server and import the downloaded RAML API Defination by selecting Add APKit components checkbox.
On clicking finish button, we can see Mule has created the project and flows are automatically created.
3. Building and running the Mule project:
To run the project Right Click on the project > Run As > Mule Application.
On successful build you can see the API console. API console is an graphical user interface of RAML used to invoke the API been deployed.
4. Sending a request to the deployed API
Enter an integer value in “Page No.” and click on “GET”
5. How mule flow works :
For Success Transaction:
For Failure Transaction (Bad Request):
APIkit Router validates the incoming request message, http method, URI and URI parameter, header and query parameters against the structure or validation defined in RAML. It also routes the message to the respective flow and serials response. Message routing consists of routing incoming API requests to existing Mule flows and returning outgoing HTTP response codes to exceptions.
APIKit Router Exceptions