RESTful API Modelling Language (RAML) is a YAML based API language to describe RESTful APIs. RAML provides a structure for developers to start their development process and helps stakeholders understand what an API does beforehand. RAML specification promotes the standardisation and reusability of an API.
API Specification is the blueprint of an API, which communicates how an API behaves. It provides all the necessary information needed to describe an API, such as:
RAML can be developed using any of the following:
When working with MuleSofts' Anypoint Studio, we recommended designing a RAML in the design centre before importing it into the Anypoint Studio for flow implementation.
The prerequisite is to create an account in https://anypoint.mulesoft.com/ to get access to the Anypoint Design Center, and follow these steps:
Yes, it can be, but we recommended starting with the API Specification as a best practice.
Resource: A unique name to identify a resource and the name should specify the usage of an API.
Method: Method of a resource to specify the operation.
Request: This contains the Request body detail and its type.
Response: This contains the Response body detail.
HTTP Status: This is the standard response code to identify the response status.
Traits and Library: A readable and reusable library.
GET (Idempotent): To obtain data.
PUT (Idempotent): To update the entire data. It can be used for both creation and updates.
POST (Not Idempotent): To create data based on the provided request.
PATCH (Not Idempotent): To update a partial instance of data.
DELETE (Idempotent): To delete data.
HEAD (Idempotent): Returns the metadata of an object for a GET response.
OPTIONS (Idempotent): Used to send the request for checking with the server for sending the cross-domain request.
A URI Param is used to identify a specific resource. It's a variable element passed as a resource.
The Query param filters the response data, passed in the URL as a key-value form.
The snippet below shows the base RAML file, including Resource fragments, type library, traits, and the RAML file hierarchy.
The following snippet shows the resource fragment, which includes the API specification of the resource.
This snippet shows the sample example and error response example hierarchy.
The below snippet shows the nested resource hierarchy, reusability of type and examples, and query parameters as traits to reuse.
The snippet shows the reuse of the type library file.
The first step is to configure the Anypoint Platform with Anypoint Studio by the below steps:
Note: Configuration can also be set from Preferences, steps as follows:
Once the configuration is set, we can download the RAML from the Design centre by following the below steps:
The RAML will be imported under the src/main/resources package, and an initial XML file (having the same name as the RAML) with APIkit router, error handler and other source flows are created.
These flows can be further implemented based on the requirement.
By building the .jar file of the API and deploying it in the Runtime Manager of Anypoint Platform, this API can be accessed by the other APIs at the enterprise level.
For the local testing, we can deploy the API locally and access it from the Postman by triggering the listener configuration set and the path.
To deploy locally:
The deployment status can be checked in the Console. Once deployed to the local system, we can test the API by any tool, such as Postman.
In the below snapshot, 8082 is the port where our API is listening. Test/* is the basepath configured, and /account is the source endpoint with query parameter customerId.
If you would like to find out more about how we can help you leverage the RAML and MuleSoft, give us a call or email us at salesforce@coforge.com.