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.
Join the DZone community and get the full member experience.
Join For FreeThis 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 API
RAML for Order API
API specifications for both the APIs are created and published to exchange:
We will also create the APIs in API Manager:Order API Weather API
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.
Global configuration along with the applied auto-discovery:
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.
A window will open in that under Mule Project -> APIs -> To the right in the APIs box, click the (+) plus symbol -> from Exchange. A new window will pop up. In that, Search for Weather API -> Add -> Finish. Once the above steps are done, then the API will be added to the APIs section, just Apply and Close to generate the Scaffold. Global configuration along with the applied auto-discovery: 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:
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:
OAuth 2.0 access token enforcement using MuleSoft is applied on Order API:
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:
Client ID and Secret not applied (Disabled):Order API
Provided authorization with the correct token:
Authorization not applied (Disabled):
This concludes the blog, giving both an idea and overview of how we can implement or create a project using two different RAML files.Published at DZone with permission of Abhishek Bathwal. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments