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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Create Proxy Application for Mule APIs
  • Create Custom DataWeave Functions in Mule 4
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve

Trending

  • Measuring the Impact of AI on Software Engineering Productivity
  • Comparing SaaS vs. PaaS for Kafka and Flink Data Streaming
  • How to Practice TDD With Kotlin
  • Scalability 101: How to Build, Measure, and Improve It
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. MULE API Kit: MULE and RAML

MULE API Kit: MULE and RAML

Here's an example of MULE and RAML working together in one potent combination.

By 
Rajesh Kumar user avatar
Rajesh Kumar
·
Jul. 13, 16 · Tutorial
Likes (10)
Comment
Save
Tweet
Share
43.2K Views

Join the DZone community and get the full member experience.

Join For Free

RAML: REST API Modeling Language. RAML is used to design and manage the whole REST API lifecycle.

MULE API Kit: Helps to build the APIs from Anypoint Studio using a RAML file.

I will be explaining the generating flows from the RAML file and executing it.

Prerequisite: Basic knowledge of RAML and basic knowledge of mule flows.

Step 1:

Create a new project in MULE.

Step 2:

Create a RAML file using the RAML API editor in Anypoint Studio (I am using version 6.0.0).

#%RAML 0.8
    title: RAMLwithMULE
    version: 1.0
    baseUri: http://localhost:8080/api

    /get:
        get:
            description: sample
            responses:
                200:
                    body:
                        text/plain:
                            example: This is get call, MULE flow from RAML
    /show:
        get:
            description: sample
            responses:
                200:
                    body:
                        text/plain:
                            example: This is get call and name show, MULE flow from RAML


Step 3:

Generate flows from RAML.  Right click on RAML file ->MULE->Generate Flows from RAML.


Step 4:

A MULE XML file will be generated based on the RAML file.

Flow xml image-

Image title

Flow XML -

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/apikit http://www.mulesoft.org/schema/mule/apikit/current/mule-apikit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    <http:listener-config name="test2-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <apikit:config name="test2-config" raml="test2.raml" consoleEnabled="true" consolePath="console" doc:name="Router"/>
    <flow name="test2-main">
        <http:listener config-ref="test2-httpListenerConfig" path="/api/*" doc:name="HTTP"/>
        <apikit:router config-ref="test2-config" doc:name="APIkit Router"/>
        <exception-strategy ref="test2-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
    </flow>
    <flow name="get:/get:test2-config">
        <set-payload value="This is get call, generated MULE flow from RAML" doc:name="Set Payload"/>
    </flow>
    <flow name="get:/show:test2-config">
        <set-payload value="This is get call and name show, generated MULE flow from RAML" doc:name="Set Payload"/>
    </flow>
    <apikit:mapping-exception-strategy name="test2-apiKitGlobalExceptionMapping">
        <apikit:mapping statusCode="404">
            <apikit:exception value="org.mule.module.apikit.exception.NotFoundException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Resource not found&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="405">
            <apikit:exception value="org.mule.module.apikit.exception.MethodNotAllowedException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Method not allowed&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="415">
            <apikit:exception value="org.mule.module.apikit.exception.UnsupportedMediaTypeException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Unsupported media type&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="406">
            <apikit:exception value="org.mule.module.apikit.exception.NotAcceptableException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Not acceptable&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
        <apikit:mapping statusCode="400">
            <apikit:exception value="org.mule.module.apikit.exception.BadRequestException" />
            <set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
            <set-payload value="{ &quot;message&quot;: &quot;Bad request&quot; }" doc:name="Set Payload"/>
        </apikit:mapping>
    </apikit:mapping-exception-strategy>
</mule>


Run the project as a MULE application and access the API.

Two methods defined in the RAML file:

  •  http://localhost:8080/api/get -output in browser -

This is a get call, generated MULE flow from RAML.

  • http://localhost:8080/api/show -output in browser -

This is get call and method name show, generated MULE flow from RAML.


MULE API

Opinions expressed by DZone contributors are their own.

Related

  • On-Demand-Schedulers With MuleSoft CloudHub APIs
  • Create Proxy Application for Mule APIs
  • Create Custom DataWeave Functions in Mule 4
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!