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

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

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

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

  • Designing a Java Connector for Software Integrations
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • Unlocking the Benefits of a Private API in AWS API Gateway

Trending

  • Segmentation Violation and How Rust Helps Overcome It
  • Building Scalable and Resilient Data Pipelines With Apache Airflow
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • Understanding Java Signals
  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
DZone Core CORE ·
Mar. 04, 17 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
19.6K 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

  • Designing a Java Connector for Software Integrations
  • Vibe Coding With GitHub Copilot: Optimizing API Performance in Fintech Microservices
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • Unlocking the Benefits of a Private API in AWS API Gateway

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!