RAMLing Around With Mule
Here's a look at Mule and RAML, including a breakdown RAML, a RESTful API Modeling Language.
Join the DZone community and get the full member experience.
Join For FreeBefore we start, we will actually look into what RAML really is.
RAML which is also called as RESTful API Modeling Language, helps us to manage the whole api lifecycle starting from it’s design, develop to sharing.It is basically build on top of YAML for describing RESTful APIs and provides all the information to describe an API. (Reference :- http://raml.org/).
How Can We Design RAML for Our APIs???

RAML can be designed in API designer. API Designer is a standalone/embeddable editor for RAML (RESTful API Modeling Language) written in JavaScript using Angular.JS.
By default, the editor uses an in-browser filesystem stored in HTML5 Local storage. API designer :- https://www.mulesoft.com/platform/api/api-designer With this tool/editor, we can design our APIs and test it there itself using a mock service with the tool.
Designing RAML for REST API
So, we need to log in into our account to start designing our APIs:-https://anypoint.mulesoft.com/#/signin If we don’t have an account we can sign up and create one.
Once we sign in, we need to click APIs menu in the top right as follows:-
If we don’t have any API present there in our account, we can create a new API by clicking the button as below:
Now, a dialog box will arrive and we will be filling it by giving our API name, Version name and an end point as follows:
So, we will be creating our first RAML in the API designer as follows:
We can see here our first simple RAML script that we designed in the API designer. This is a simple GET method example which will take a query parameter and display the response in JSON.
If we see the code, we can see there is it starts with the following:
#%RAML 0.8
title: TestAPI
baseUri: http://9090/testmyapi
version: 1.0
This is called the ROOT and contains the basic information of the API. The baseUri is the url where the API will be host and will be used in every call made to the API .
The next part contains the following:
/books:
displayName: Book
description: Description on Book
get:
displayName: Products
description: Test
queryParameters:
author:
displayName: Author
type: string
description: An author's full name
example: Anirban
required: false
It contains the resource, method and the query parameter. Here the resource is books, method is GET and the query parameter is author
The last part consists of the response design as following:
responses:
200:
body:
application/json:
example: |
{
"success": true,
"message": "Hi This is your first RAML"
}
We can see the design of response which shows here that when the response status will be 200, above format of response will be generated.
In fact we can put our response structure from an example as above or from a schema or even from a data model introduced in new RAML 1.0.We can also put our response format here for different status code.
Testing Our API
Infact API designer platform provides an option to test our APIs that we build in it. In the left side we can see a button called Mocking Service, if we on that button, the API will be ready for a mock test. You can see in the code, that our baseUri has been commented and a new mock Uri is generated.
So, to test the API, we need to hit Try it button in the right side, that display our API graphically:
After hitting Try it button we need to fill the API with required parameter like query parameter in our case and then hit the GET method button.
We can see our response is generated with status code 200:
We can save our RAML file in the API designer by hitting the Save button.
Conclusion…..
So we can see it is very very easy to design and create a RAML file for our RESTful api.The API designer helps us greatly in designing as well as testing the API we create.
Now, you can experiment in your own way and design RAML and implement the example.
Please do share your feedback and experiences in the below section for comments.
Opinions expressed by DZone contributors are their own.
Comments