In this article we will see how we can create or generate Mule 4 project using RAML.
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

import-raml-anypointstudio

Step 3: Building and Running Mule Project

Right click on the project –> Run As –> Mule Application

run-mule-app
Step 4: Test your deployed App through API Console

API-console

Step 5: Check Success Scenario

Success Test 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.
Success response flow

Step 6: Check Error Scenario
Error Test through API console

Flow execution sequence in Error Scenario(Bad Request)
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
Error response flow
Below are some error codes and their meanings which we normally uses in our development.
HTTP Error Code List Description

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

By Manish Kumar

I am having around 10 years of IT experience in Integration Architecture, Requirement gathering, Effort Estimation, Application Design\Development\Testing and Deployment including 5+ years of experience in MuleSoft ESB and Hybrid Integrations. DevOps and Cloud Integration is my area of interest.

Leave a Reply

Your email address will not be published. Required fields are marked *