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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building Multi-Rail Payment Failover to Stop Latency Spikes and Double Debits
  • GET, POST, PUT, DELETE: Choosing HTTP Verbs in a Real .NET Core Web API, Not Just by the Textbook
  • Delegated Transport, Forked Authorization: Where Chat and AI-Agent Integrations Actually Break
  • A Non-Expiring AKS Deployment Token Could Read Secrets Across Three Namespaces

Trending

  • Guess the Speed: Building a Family Internet Speed Guessing Game
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java
  • Solving Comprehension Debt in AI-Generated Codebases
  • Beyond @Transactional: Solving the Dual-Write Problem in Distributed Microservices

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Combining Different API Specifications to a Single API in Mule 4

Combining Different API Specifications to a Single API in Mule 4

This blog aims to give an idea of how we can implement two different API specifications or two different RAML in one application.

By 
Abhishek Bathwal
·
Jan. 24, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
9.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

This blog aims to give an idea of how we can implement two different API specifications or two different RAML in one application. As well as generate two different main flows with different resources along with applying two different policies to each API.

So, let's first create two different API Specifications:

RAML for Weather APIWeather API/master

RAML for Order APIOrder API/master

API specifications for both the APIs are created and published to exchange:

Projects and Assets UIs

We will also create the APIs in API Manager:

API Manager UI

Order API Weather API

Order API v1 and Weather API v2

As the API is created and published. The next step will be creating the project in studio.

Creating the Project

We will first take the Order API and generate the flow for it.

Generating the flow for the Order API

Global configuration along with the applied auto-discovery:

Global configuration and auto-discovery configuration

One part is done: the implementation of Order API.

Now the second part is to add the RAML for Weather API.

Limitation: Two different RAML cannot be generated from a single API folder. One may overwrite the other.

So to overcome this, we need to import the RAML for Weather API as a module.

Import Weather API

For that, right-click on the Project -> Manage Dependencies -> Manage Modules.

Manage Dependencies > Manage Modules

A window will open in that under Mule Project -> APIs -> To the right in the APIs box, click the (+) plus symbol -> from Exchange.

Properties for dual-api

A new window will pop up. In that, Search for Weather API -> Add -> Finish.

'A new window will pop up'

Once the above steps are done, then the API will be added to the APIs section, just Apply and Close to generate the Scaffold.

Mule Project > APIs

Confirmation promptThe Weather API will be added as a module to the existing project, and the flow will be generated:

Added Weather API module

Global configuration along with the applied auto-discovery:

Global configuration and auto-discovery configuration (2)

As both the APIs are in a single project, the combined global element for both the APIs to a single global.xml along with the same HTTP config but two different paths.

Global Config:

Global configuration elements > HTTP Listener config

Path for Order API and Weather API:

Path for Order API and Weather API

The project is ready now that all the basic configurations are done.

The next step is to apply a policy, deploy and test the application.

Apply Policy and Deploy the API

Client ID enforcement is applied on Weather API:

Weather API v2

OAuth 2.0 access token enforcement using MuleSoft is applied on Order API:

Order API v1

Deployed project on CloudHub:

Deployed project on CloudHub

The policies are applied successfully and deployed too.

As a next step, the API will be tested.

Testing

Client ID and Secret applied:

test 1: Client ID and Secret applied

Client ID and Secret not applied (Disabled):

test 2: Client ID and Secret not applied

Order API

Provided authorization with the correct token:

test 3: provided authorization with correct token

Authorization not applied (Disabled):

test 4: authorization not applied

This concludes the blog, giving both an idea and overview of how we can implement or create a project using two different RAML files.


API

Published at DZone with permission of Abhishek Bathwal. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building Multi-Rail Payment Failover to Stop Latency Spikes and Double Debits
  • GET, POST, PUT, DELETE: Choosing HTTP Verbs in a Real .NET Core Web API, Not Just by the Textbook
  • Delegated Transport, Forked Authorization: Where Chat and AI-Agent Integrations Actually Break
  • A Non-Expiring AKS Deployment Token Could Read Secrets Across Three Namespaces

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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