Mule 4 Mulesoft Basics Mulesoft Tutorial

Creating Mule 4 Project with RAML

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:

  1. Endpoint URL with its Query parameters and URI parameters,
  2. HTTP methods to which API is listening to (GET, POST, PUT, DELETE),
  3. Request and response schema and sample message,
  4. HTTP response code that an API will return (eg: 200, 400, 404, 500).

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”

mule_raml_project_success_request

Response:
mule_raml_project_success_response

5. How mule flow works :


For Success Transaction:
On API console, when we click on “GET”

  1. our request is send to the HTTP endpoint
  2. where an HTTP listener forwards the request to APIKit Router.
  3. APIKit Router validates the request and the method which we are calling.
  4. and send the request to the relevant flow i.e. “get:/user/queryuser:tutorialsAtoZ-config”;
  5. where are request is processed and we get a success response.

For Failure Transaction (Bad Request):
On API console, when we click on “GET”

  1. On entering and incorrect value in Page No. (eg: “A”) and clicking “Force GET”
  2. our request is send to the HTTP endpoint
  3. where an HTTP listener forwards the request to APIKit Router.
  4. APIKit Router validates the request and the method which we are calling.
  5. On validation failed APIKit router through an error
  6. which is caught by “apiKitGlobalExceptionMapping” through “Reference Exception Strategy”
  7. 400 Flow catches the error, process it and send an error response.

mule_raml_project_400_resquest

 

APIKit Router


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


mule_apikitroute_exception

Varun Goel

About Varun Goel

Varun Goel is a technology enthusiast with 6+ years exp in IT industry. In fact, he is been developing application after schooling as freelancer. Currently working with one of the Fortune’s 100 Companies having vast experience Mule ESB, Tibco, HTML5, CSS, JSS, Android, Core Java, JSP, PHP, MySQL, AutoCAD, Maya, ZBrush, Photoshop, Flash CS and many more.

Leave a Reply

Your email address will not be published.