How to Create a RAML!

 Hello Mule'es,

        From this blog, you will get to know, how to Create a RAML.

What is RAML?

RAML stands for RESTful API Modeling Language. It describes about API which is easily readable by 

both human and computers.

Now, I have created a Customer-API, which consists of 4 endpoints( getCustomer, addCustomer, 

updateCustomer and deleteCustomer) with 4 methods get, post, put and delete respectively.

Before Creating an API, I created a Fragment that includes examples, types, traits. 

please refer the below screen shots.

                                          

img: 1-Fragment

 Examples:  This consists of Requests and Responses.


img-2 

requests:

These requests contain sample Json payload, so that whatever the data you are sending, it should be in 

that particular format.

For instance, Sample payload:
[
    {
        "customer_Id": "894H1",
        "firstName": "Nikhil",
        "lastName": "Siddarth",
        "company": "Google",
        "city": "Delhi",
        "state": "Uttar Pradesh",
        "country": "India"
    }
]


responses:

responses include error Response and success Response.

Error Response:

    This will help whenever any error occurs.

    Errors might be BAD REQUEST, METHOD NOT ALLOWED, NOT IMPLEMENTED,

 RESOURCE NOT FOUND etc.


    
img-3

        For instance: Error Response be like

{
  "statusCode":"400",
  "errorMessage":"400-Bad Request" 
}

Here Http status code for the Bad Request is 400, So In this way, we define all

the error Responses.

img- 4

Success Response:

If the flow was executed successfully, then we will get the message which we define here!



img-5


For Instance:

{
  "message""Successfully fetched All Customer details."
}

Traits:

These are the reusable components which defines common characteristics and can used

across an API.

img-6




        In client Enforcement, we will define the ClientID and client secret.

        For Instance:


                        #%RAML 1.0 Trait
            headers:
              client_id:
                 type: string
                 required: true
                 example: Ajay
              client_secret:
                 type: string
                required: true
                example: Ajay@123

ErrorTrait:

    This is just calling of the Errors. please refer the below screen shot for your

reference.



img-7



Types:

    This defines the type of the data. We already define sample payload in examples, hence we define

the data type for that! Please refer the below screen shot for the reference.
 

    



        
img-8



img-9



Finally, we define Customer Fragment as a library.

It means we define multiple data types and that can be referred from RAML file.


img-10


    Now, Creating the Customer API having 4 end points with 4 methods.


img- 11

img- 12


img - 13


You can also refer Customer API, here is the link:



After creating the Customer API, you need to publish to Exchange. Make sure that you need to check 

the "include unreferenced files". 

This is how we create a simple RAML & publish to Exchange.

I hope this blog is helpful!

If any queries, please reach out and drop an email to bodhini2002@gmail.com.


 Happy Learning!

Thanks & Regards,
Bodhini







        

Comments

Post a Comment

Popular posts from this blog

How to Create Alert Notification!

Deploying in Cloud Hub!