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" }
© 2020 goformule.com

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave