RESTful API Modeling Language (RAML) is a language intended to describe RESTful APIs. RAML is written in the YAML human-readable data serialization language. The RAML effort was first proposed in 2013 and garnered support from technology leaders like MuleSoft, AngularJS, Intuit, Box, PayPal, Programmable Web and API Web Science, Kin Lane, SOA Software, and Cisco. The goal of RAML is to provide all the necessary information to describe RESTful APIs, thus providing a simpler way to design APIs.
A sample RAML file of the Notes Example API (courtesy of MuleSoft) is shown below.
#%RAML 0.8
title: Notes Example API
version: v2
mediaType: application/json
documentation:
- title: Overview
content: This is an example of a simple API for a "notes" service
/notes:
description: A collection of notes
get:
description: List all notes, optionally filtered by a query string
queryParameters:
q:
description: An optional search query to filter the results
example: shopping
responses:
200:
body:
example: |
[ { "id": 1, "title": "Buy some milk", "status": "done" },
{ "id": 2, "title": "Return sweater", "status": "overdue", "dueInDays": -2 },
{ "id": 3, "title": "Renew license", "status": "not done", "dueInDays": 1 },
{ "id": 4, "title": "Join gym", "status": "not done", "dueInDays": 3 } ]
post:
description: Create a new note in the collection
body:
example: |
{ "title": "Return sweater", "dueInDays": -2 }
headers:
X-Tracking-Example:
description: You can specify request headers like this
enum: [ accounting, payroll, finance ]
required: false # require it by changing this to true
example: accounting
responses:
201:
headers:
X-Powered-By:
description: You can describe response headers like this
example: RAML
body:
example: |
{
"id": 2,
"title": "Return sweater",
"status": "overdue",
"dueInDays": -2
}
/{id}:
description: A specific note, identified by its id
uriParameters:
id:
description: The `id` of the specific note
type: number
example: 2
get:
description: Retrieve the specified note
responses:
200:
body:
example: |
{
"id": 2,
"title": "Return sweater",
"status": "overdue",
"dueInDays": -2
RAML itself provides a full API design lifecycle, broken into five categories.
Design
By use of the easy-to-read YAML format, API design can become more visual than prior API development approaches. Utilizing a dedicated RAML tool (API Workbench, API Designer) or IDE plug-in (Sublime, Visual Studio) facilitates faster development, eliminating code duplication and providing functionality to prototype and perfect APIs being developed.
With the building blocks in place for an API inside the RAML file, mock data can be added to allow for prototyping and testing before any actual program code is written. As a result, designers can sit with stakeholders and product owners to validate the API early in the development process.
Build
With the design of the RAML file in place, the actual programming of the API logic can begin. At this point, the RAML file becomes a specification and popular languages like NodeJS, Java, .NET, Mule, and IOT Noble can simplify the build process.
Below is an example based in Java and the RAML for JAX-RS framework:
@Path(“/notes”)
public interface NotesExampleResource
{
@POST
@Consumes(“application/json”)
Response createNote(Note note, @Context UriInfo
uriInfo);
@GET
@Produces(“application/json”)
Notes getNotes(@QueryParam(“q”) String query,
@Context UriInfo uriInfo);
...
}
Using the RAML for JAX-RS framework, it is possible for Java interfaces to generate a RAML file, as well, which provides another option for leveraging the RAML specification.
Test
With the design and build phases in place, the next logical step in the API Development Lifecycle is the testing stage. These unit tests are critical to making sure that the API being developed maintains any backward compatibility while also meeting all the current requirements.
Tools like Abao, Vigia, and Postman allow RAML specifications to be imported, leading to setup scripts and tests being created to validate the API. Additionally, testing services (like API Fortress, API Science, and SmartBear) provide assistance toward testing latency, responses, payloads, and errors.
Document
API documentation has been a challenge, with tools like Swagger and Miredot often falling short at providing complete information and leading us to rely on developers to specify cryptic annotations and language-specific documentation like JavaDocs.
With the RAML specification keeping documentation as a core priority, the documentation is kept in sync with the code itself. This refreshing benefit is due to the fact that the RAML specification serves as an interface (or contract) for the API itself – in sync with the underlying business logic providing results for the service.
Tools like API Console, RAML to HTML, and RAML2HTML for PHP provide quick and easy ways to expose standardized documentation – which can be kept private on a corporate intranet or available for public consumption.
Share
With all the building blocks in place in the API Development Lifecycle, the final segment focuses on sharing the API. The RAML specification introduces several ways in which APIs can be integrated.
SDK Generation: Languages like Java, .NET, PHP, Ruby, NodeJS, iOS, Windows, and Go provide push-button functionality to build Software Development Kits (SDKs) automatically using the RAML file.
Third Party Tooling: Oracle and MuleSoft include RAML functionality into their toolsets to provide the ability to connect to any API utilizing RAML just by pasting in the specification.
API Notebook: Provides an environment for developers to test APIs, manipulate results from API calls, and connect to multiple APIs using the JavaScript language.
RAML 0.8 v 1.0
RAML specification 0.8 continues to be the current standard, but version 1.0 began gaining momentum in September 2016. Version 1.0 includes the following updates.
Data types: Provides a unified and efficient way to model API data with support for sub-schemas.
Examples: Multiple examples and allowing annotations to facilitate injection of semantics.
Annotations: Incorporating the proven pattern to allow for extensibility.
Libraries: Improved modularity to promote API artifact reuse.
Overlays/extensions: Allowing use of separate files to increase extensibility.
Improved security schemas: Additional OAuth support and key-based schemas.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}