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 Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • You Don't Get to Retrofit Trust: Why API Security Must Be Designed In, Not Bolted On
  • Designing API-First EMR Architectures in .NET: Enabling Modular Growth in Compliance-Driven Systems
  • How Retry Storms Crash API-Led Systems: Bounded Reliability Patterns for Distributed Architectures
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack

Trending

  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • LLM Integration in Enterprise Applications: A Practical Guide
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Publish RAML-Based APIs to Anypoint Exchange

How to Publish RAML-Based APIs to Anypoint Exchange

Anypoint Exchange can be connected with Anypoint Studio to download and install connectors, consume APIs, and publish RAML-based APIs.

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Mar. 04, 17 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
20.0K Views

Join the DZone community and get the full member experience.

Join For Free

Anypoint Exchange is home to a complete listing of your connectors, APIs, templates, and examples. Anypoint Exchange is a hub where you can find connectors, APIs, examples, and much more. You can connect to Exchange with Anypoint Studio to download and install connectors, consume APIs, etc.

Publish APIs to Anypoint Exchange

Sign into Anypoint Mulesoft Platform and go to Exchange. Make sure you have access to Exchange. This can be verified under Access Management > Users.

Now, click Add Item and select REST API from the drop-down list. It will navigate you to another page.

Image title

Provide details like Item Name and Item ID (auto-generated). Other fields are optional. Click on Add Version at the end of the page. It will ask you to provide details like REST API Spec Version, API Version, API Portal, and REST API URL. You can get the API Portal and Rest API URL from your Live Portal. Click Done.

Image titleFinally, click Save new item. This will navigate you to a new page from there you can publish Rest API to Exchange.

Image title

Now, click Request to publish and it will publish your API to Exchange.

Image title

This is how you can publish your API and any other item to Exchange.

Image title

Consume REST APIs Using Anypoint APIKit

Go to Anypoint Studio and go to File > New > Mule Project and it will open a pop-up window. Provide the Project Name and check Add APIKit Component.

Click the ellipsis button near API Definition. It will show a drop-down list. Select Anypoint Platform. It will open new pop-up window.

Image title

Now, click Add Credentials and sign in with your Anypoint Platform account.

Image title

Once you will sign in, you can see a list of all APIs associated with your account. Select the API which you want to consume and Press OK. Finally, click on Finish.

Image title

This will generate various flows like API Main, API Console, Exception Strategy and various flows depending on HTTP method defined in your API.

API Main and Console Flow

The main flow performs the below function:

  • Exposes API using HTTP or Jetty.

  • Routes request between interfaces and backend flows depending on the HTTP request.

  • References exception strategies that produce HTTP-status-code responses.

Image title

Backend Flows

APIKit generates the backend flows for each request-action pairing in RAML.

Image title

Exception Strategy

APIKit generates the Exception Strategy flow for various response codes.

Image title

<?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="api-httpListenerConfig" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
	<apikit:config name="api-config" raml="api.raml" consoleEnabled="false" doc:name="Router"/>
	<flow name="api-main">
		<http:listener config-ref="api-httpListenerConfig" path="/api/*" doc:name="HTTP"/>
		<apikit:router config-ref="api-config" doc:name="APIkit Router"/>
		<exception-strategy ref="api-apiKitGlobalExceptionMapping" doc:name="Reference Exception Strategy"/>
	</flow>
	<flow name="api-console">
		<http:listener config-ref="api-httpListenerConfig" path="/console/*" doc:name="HTTP"/>
		<apikit:console config-ref="api-config" doc:name="APIkit Console"/>
	</flow>
	<flow name="put:/users/books:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<flow name="put:/users/books/{bookTitle}:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<flow name="delete:/users/books/{bookTitle}:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<flow name="get:/users/authors:api-config">
		<set-payload value="{&#xA;&quot;authorID&quot;:1,&#xA;&quot;authorName&quot;:&quot;Michael Lynn&quot;,&#xA;&quot;DOB&quot;:&quot;21/04/1986&quot;,&#xA;&quot;Age&quot;:30&#xA;}" doc:name="Set Payload"/>
	</flow>
	<flow name="get:/users/authors/{authorID}:api-config">
		<set-payload value="{&#xA;&quot;TotalBooks&quot;:30,&#xA;&quot;Subject&quot;:&quot;Maths,SCience&quot;,&#xA;&quot;Publication&quot;:&quot;Nirvana&quot;&#xA;}" doc:name="Set Payload"/>
	</flow>
	<flow name="get:/users/books:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<flow name="get:/users/books/{bookTitle}:api-config">
		<set-payload value="{&#xA;&quot;id&quot;: &quot;SbBGk&quot;,&#xA;&quot;title&quot;: &quot;Stiff: The Curious Lives of Human Cadavers&quot;,&#xA;&quot;description&quot;: null,&#xA;&quot;datetime&quot;: 1341533193,&#xA;&quot;genre&quot;: &quot;science&quot;,&#xA;&quot;author&quot;: &quot;Mary Roach&quot;,&#xA;&quot;link&quot;: &quot;http://e-bookmobile.com/books/Stiff&quot;&#xA;}" doc:name="Set Payload"/>
	</flow>
	<flow name="get:/users/books/{bookTitle}/author:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<flow name="get:/users/books/{bookTitle}/publisher:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<flow name="post:/users/authors:api-config">
		<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
		<set-payload value="{&#xA;&quot;message&quot;:&quot;Author updated {but not really&quot;&#xA;}" doc:name="Set Payload"/>
	</flow>
	<flow name="post:/users/books:api-config">
		<set-payload value="#[NullPayload.getInstance()]" doc:name="Set Payload"/>
	</flow>
	<apikit:mapping-exception-strategy name="api-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>

You can go through my articles about designing RAML-based APIs with API Manager and creating API portals for more information!

Now, you know how to publish APIs to Anypoint Exchange and consume them using APIKit!

API

Opinions expressed by DZone contributors are their own.

Related

  • You Don't Get to Retrofit Trust: Why API Security Must Be Designed In, Not Bolted On
  • Designing API-First EMR Architectures in .NET: Enabling Modular Growth in Compliance-Driven Systems
  • How Retry Storms Crash API-Led Systems: Bounded Reliability Patterns for Distributed Architectures
  • Self-Hosted Inference Doesn’t Have to Be a Nightmare: How to Use GPUStack

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook