DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. RAMLing Around With Mule

RAMLing Around With Mule

Here's a look at Mule and RAML, including a breakdown RAML, a RESTful API Modeling Language.

Anirban Sen Chowdhary user avatar by
Anirban Sen Chowdhary
·
Feb. 16, 16 · Analysis
Like (11)
Save
Tweet
Share
10.62K Views

Join the DZone community and get the full member experience.

Join For Free

Before we start, we will actually look into what RAML really is.

RAML which is also called as RESTful API Modeling Language, helps us to manage the whole api lifecycle starting from it’s design, develop to sharing. It is basically build on top of YAML for describing RESTful APIs and provides all the information to describe an API. (Reference :- http://raml.org/).

How Can We Design RAML for Our APIs???
Image title


RAML can be designed in API designer. API Designer is a standalone/embeddable editor for RAML (RESTful API Modeling Language) written in JavaScript using Angular.JS.

By default, the editor uses an in-browser filesystem stored in HTML5 Local storage. API designer :- https://www.mulesoft.com/platform/api/api-designer With this tool/editor, we can design our APIs and test it there itself using a mock service with the tool.

Designing RAML for REST API

So, we need to log in into our account to start designing our APIs:-https://anypoint.mulesoft.com/#/signin  If we don’t have an account we can sign up and create one.

Image title

Once we sign in, we need to click APIs menu in the top right as follows:-

Image title

If we don’t have any API present there in our account, we can create a new API by clicking the button as below:

Image title

Now, a dialog box will arrive and we will be filling it by giving our API name, Version name and an end point as follows:

Image title

So, we will be creating our first RAML in the API designer as follows:

Image title

We can see here our first simple RAML script that we designed in the API designer. This is a simple GET method example which will take a query parameter and display the response in JSON.

Image title

If we see the code, we can see there is it starts with the following:

#%RAML 0.8

title: TestAPI

baseUri: http://9090/testmyapi

version: 1.0

This is called the ROOT and contains the basic information of the API. The baseUri is the url where the API will be host and will be used in every call made to the API .

The next part contains the following:

/books:

    displayName: Book

    description: Description on Book 

   get:

    displayName: Products

    description: Test 

   queryParameters:

    author:

      displayName: Author

      type: string

      description: An author's full name

      example: Anirban

      required: false

It contains the resource, method and the query parameter. Here the resource is books, method is GET and the query parameter is author

The last part consists of the response design as following:

responses:

       200:

        body:

           application/json:

              example: |

                 {

                     "success": true,

                      "message": "Hi This is your first RAML"

                    } 


We can see the design of response which shows here that when the response status will be 200, above format of response will be generated.

In fact we can put our response structure from an example as above or from a schema or even from a data model introduced in new RAML 1.0. We can also put our response format here for different status code.

Testing Our API

Infact API designer platform provides an option to test our APIs that we build in it. In the left side we can see a button called Mocking Service, if we on that button, the API will be ready for a mock test. You can see in the code, that our baseUri has been commented and a new mock Uri is generated.

Image title

So, to test the API, we need to hit Try it button in the right side, that display our API graphically:

Image title

After hitting Try it button we need to fill the API with required parameter like query parameter in our case and then hit the GET method button.

Image title

We can see our response is generated with status code 200:

Image title

We can save our RAML file in the API designer by hitting the Save button.

Image title

Conclusion…..

So we can see it is very very easy to design and create a RAML file for our RESTful api.The API designer helps us greatly in designing as well as testing the API we create.

Now, you can experiment in your own way and design RAML and implement the example.
Please do share your feedback and experiences in the below section for comments.

API

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Distributed Tracing: A Full Guide
  • Testing Level Dynamics: Achieving Confidence From Testing
  • Introduction To OpenSSH
  • 19 Most Common OpenSSL Commands for 2023

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: