RAML (RESTful API Modelling Language) 1.0 Basic Example



RAML 1.0

RAML stands for RESTful API Modelling Language.We can make RAML for following purposes :

1. It is basically an api specification.
2. If api A is consumed by api B then it is standard contract between these two apis.
3. It is also serves as api documentation.
4. We can mock or api by raml.
5. We can generate api interfaces by using raml.

So we should make a good raml to specify all the required things between the apis.

for making RAML we need to log in to anypoint platform.There we have to go to Design Center.In Design Center create new file as shown below :




Below is the example of a simple raml api specification.This api is performing CRUD operations in a table of employee database.


  • first line is raml version which is 1.0
  • second line is title of api which Employee API
  • v1 is api version
  • /person is resource name which is common for all operations(CRUD).
  • get,post,put,delete are http methods.
  • we can give description of any operation,api,etc.Here we are using description under http method so it gives description of operation perform by http method.
  • displayName is name of resource which is used in api.
  • responses contains response attributes like http server code,body,response format,examples,etc.
  • under response we can define http server code like 200,201,etc.
  • under response, body attribute defines response body.
  • we can define response format also which is application/json in our api.
  • example is the actual output response.

Once RAML is completed we can download it and import it into our project in src/main/resources in anypoint 7 or src/main/api in anypoint 6. 

We can also directly connect with anypoint platform by API sync in anypoint studio.



#%RAML 1.0 title: Employee API
version: v1 /person: get: description: get data of all persons displayName: person responses: 200: body: application/json: example: [{ "id" : 1, "firstName" : "Rahul", "lastName" : "Singh", "city" : "Mumbai" }] post: description: insert data of persons displayName: person responses: 201: body: application/json: example: { "data" : "Data is inserted successfully" } put: description: update data of persons displayName: person responses: 204: body: application/json: example: { "data" : "Data is updated successfully" } delete: description: delete data of persons displayName: person responses: 200: body: application/json: example: { "data" : "Data is deleted successfully" }