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

RAMLing Around With Mule ( Part 2 )

Check out this guide to RAMLing with Mule, focusing this time on how to use RAML in Anypoint, and testing our API.

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

Join the DZone community and get the full member experience.

Join For Free

In the first part of this series, we discussed what RAML really is and how can we use this specification for designing, creating and testing the APIs for our RESTful services. If you are wondering where to find the first part, then here it is:

https://dzone.com/articles/ramling-around-with-mule

In this part, we will see how to use the RAML we created in our previous article with Mule ESB or simple in our Anypoint Studio.

To use an existing RAML file with our Mule application, we need to have APIKit plugins in our studio.

When we create a new APIKit project and click Finish, Anypoint Studio uses the imported RAML file to automatically generate skeletal backend flows, one for each resource-action pairing in the RAML file.

Also, Studio pre-populates each of the flows with one or more message processors which perform "mock" activities based on the content of the example response included with each resource-action pairing in the RAML file.

Reference: https://docs.mulesoft.com/anypoint-platform-for-apis/apikit-beyond-the-basics
Image title

How to Use RAML in Our Anypoint Studio???

We need to go back our API designer where we had created and tested our RAML. We need to click Export as shown below: 

Image title

Please ensure the Mocking service button is off or else it will create Mock URL. We will see our RAML file is downloaded in our local system as a Zip file. We need to extract the file and use the .raml file generated.

Using RAML in Our Anypoint Studio

In Anypoint Studio, We create a new Mule project as below:

Image title

Let’s give the project name as TestRAML, and add APIKit component in the project and refer our RAML file from our local system, where we downloaded the file from API designer:-

Image title

Once we click finish button, we can see Mule has created the project and flows are automatically created based on our RAML file we created:-

Image title

If we go into the code, we will find the RAML file has created different types of flows and exception strategy with the APIKit :

Image title

If we see our code thoroughly we will find that the APIKit plugin has divided the flow into 2 parts as our RAML file described. It contains the main flow which exposes the API with the HTTP listener and the APIKit router route the request to flow called get:/books:api-config. Since, we only have one resource defined in our RAML, it is routed to only one flow created:

Image titleIt also has an exception strategy where different exceptions are defined and is routed to that particular exception whenever any exception occurs.

Here you can see different exception defined and it is automatically generated by APIKit plugin:

Image title

Testing Our API

We will be running our Mule project as Mule application :-

Image title

So, to test the API, we can see APIKit Console has started:

Image title

If we don’t want to test our APIs there, then we can also test the APIs in a browser with the APIKit console. This console is provided by APIKit to test our APIs. For that we need to copy that URL and paste it in our browser directly:

Image title

We can see the APIKit console in our browser after putting the URL there. Now, we are ready to test our API in the browser with API console:

Image title

So, finally after filling the query param and then hitting the GET button we get our response:

Image title

Conclusion…

So we can see it is very very easy to create a RESTFul apis in our Anypoint Studio with a RAML file. With the help of APIKit plugin it gets very simple in designing and testing our APIs .

I hope you like this article on implementing RAML in our Anypoint Studio and I am looking forward to see your feedback in comment section.

Flow (web browser)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Introduction to Spring Cloud Kubernetes
  • Getting a Private SSL Certificate Free of Cost
  • Specification by Example Is Not a Test Framework
  • Use Golang for Data Processing With Amazon Kinesis and AWS Lambda

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: