VOOZH about

URL: https://dzone.com/articles/design-raml-based-rest-api-using-mulesoft-anypoint

โ‡ฑ How to Design a RAML-Based REST API With Mulesoft Anypoint API Manager


Related

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. How to Design a RAML-Based REST API With Mulesoft Anypoint API Manager

How to Design a RAML-Based REST API With Mulesoft Anypoint API Manager

There are tons of benefits to creating RAML-based REST APIs, including standardization, reusability, and easy readability.

By Updated Mar. 27, 17 ยท Tutorial
Likes
Comment
Save
79.0K Views

Join the DZone community and get the full member experience.

Join For Free

RAML (Rest API Modeling Language) is based on YAML format, which is used to design REST APIs. RAML provides various features, including standardization, reusability, easy readability, and much more. 

Now, we will walk through how to create REST APIs using API Manager.

1. Create an Anypoint MuleSoft Account

Create an Anypoint MuleSoft account and sign into the Anypoint MuleSoft platform.

2. Add a New API

First, go to API Manager as shown below:

๐Ÿ‘ API Manager

Click API Manager to reach the API Manager Screen. Then, click Add New API. Fill in the details like API name and Version name. Description and API endpoint are optional.

๐Ÿ‘ Image title

After filling in these details, click Add.

3. Define the API

Next, click Define API in the API Designer.

๐Ÿ‘ Image title

We will be navigated to API Manager Designer, where we can start writing the RAML. We can see the documentation on the right side, depending on the RAML we are writing.

On the left side, we can see the RAML file name. By default, the file name will be api.raml. We can rename the RAML filename by right clicking on api.raml. The extension of a RAML file is always .raml.

๐Ÿ‘ Image title

We can see title and version have already been defined by default at the root level. Title and Version will be the same, as we mentioned in Step 2. Now, we can start defining the RAML.

๐Ÿ‘ Image title

As we are writing the RAML, we can see the documentation being generated on the right side of the screen.

๐Ÿ‘ Image title

4. Test the API from API Manager

We need to enable Mocking Service for testing the API. Once we will enable the mocking service, then baseURI will be added to the RAML.

๐Ÿ‘ Image title

After enabling the mocking service, we can test the REST API by clicking on any of the HTTP methods on the right side of the screen. Then, click Try it!.

๐Ÿ‘ Image title

RAML Example

#%RAML 0.8
title: Book Service API
version: 1.0
/users:
 /authors:
 description: This is used to get authors details
 get:
 responses: 
 200:
 body:
 application/json:
 example: |
 {
 "authorID":1,
 "authorName":"Robert",
 "DOB":"21/04/1986",
 "Age":30
 } 
 post:
 body: 
 application/json:
 example: |
 {
 "authorID":1,
 "authorName":"Stephen",
 "DOB":"21/04/1986",
 "Age":30
 } 
 responses: 
 201:
 body: 
 application/json:
 example: |
 {
 "message":"Author updated {but not really"
 }
 /{authorID}:
 get:
 responses: 
 200:
 body: 
 application/json:
 example: |
 {
 "TotalBooks":30,
 "Subject":"Maths,Science",
 "Publication":"Nirvana"
 }
 /books:
 get: 
 post:
 put:
 /{bookTitle}:
 get:
 queryParameters: 
 author:
 displayName: Author
 description: The Author's Full Name
 type: string
 required: false
 example: Michael Lynn
 publicationYear:
 displayName: Publication Year
 description: Year of Publication
 type: number
 required: false
 example: 2010
 rating:
 displayName: Rating
 description: Average Rating of book submitted by users (1-5)
 type: number
 required: false
 example: 3.5
 isbn:
 displayName: ISBN
 description: ISBN Number of Book
 type: string
 maxLength: 10
 example: 1234567
 required: false
 responses: 
 200:
 body: 
 application/json:
 example: |
 {
 "id": "123",
 "title": "API Design",
 "description": null,
 "datetime": 1341533193,
 "author": "Mary"
 }
 put:
 delete:
 /author:
 get:
 /publisher:
 get:

And we're done! Now you know how to create REST APIs using API Manager. Please refer to another article for publishing your API to Anypoint API Portal. Here's a video tutorial:

API REST Web Protocols MuleSoft Design

Opinions expressed by DZone contributors are their own.

Related

  • Level Up Your API Design: 8 Principles for World-Class REST APIs
  • GraphQL vs REST API: Which Is Better for Your Project in 2025?
  • API Design First: AsyncAPI in .Net
  • MuleSoft Integrate With ServiceNow

Partner Resources

ร—

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: