Using API instance in Anypoint Platform 2
In this article, I am going to explain the main purpose of API instance and its use in the Anypoint Platform.
Join the DZone community and get the full member experience.
Join For FreeIntroduction
In this article, I am going to explain the main purpose of API instance and its use in the Anypoint Platform. This is a follow-up article of the previous one.
What is API Instance?
Imagine the Java class paradigm. Multiple objects can be created from a single Java class. Approximately the same principle applies to this API instance concept. Let's suppose that our API (The RAML specs that we created in Design Center and published in the Exchange as an asset) is the Java class. Now we can create multiple instances from the API in multiple environments. Just imagine something as shown below to get an idea.
What's the Use of it?
You can create various instances of the same API and apply different policies to them separately. Please check the documentation.
How to Use it?
It's kind of hit and miss to find out how to make proper use of it as the official documentation of Mule has not provided yet a proper roadmap of API development. So, here are the basic steps you need to do. (Please read my previous article for more detail).
Step 1
Create an instance of the API.
Here, I'm creating an API instance named demo-instance
Step 2
Once the API instance is created, you will get an API instance ID. Implement the API in Anypoint Studio. In the implementation, you configure API Autodiscovery and provide the API instance ID. By doing so, you are telling the Anypoint Platform to automatically wire that instance of the API to the implementation.
Step 3
Once the application is deployed, copy the URL of the application. Now go the Exchange and look for the API asset. Navigate to API instances option of the API and configure the instance demo-instance with the implementation URL. Here is a snapshot:
Step 4
Once the API instances are defined, you can choose them to be executed for the API. Here is a screenshot:
In the figure above, we are executing the GET operation of the resource against the API instance chosen (demo-instance). All statistics for this operation will be registered in that particular instance.
Conclusion
It's easy to make use of the API instance in the Anypoint Platform.
A Small Experiment:
I performed a small experiment by creating two API instances (Basic Endpoint) for the same API and configuring two API Autodiscovery elements (providing the API instance IDs in the implementation. Here is the screenshot:
On deploying the application to Cloudhub, the instances were successfully auto-discovered.
Issue 1
I have configured the instances in Exchange for the API and made calls to an API operation for both of the instances. But unfortunately, only one of the instances registered the statistics.
Issue 2
Applied Client Id enforcement policy on instance-one. Unfortunately, the policy is applied to instance-two also automatically.
Remark
I will try to resolve this issue and write another article on it.
Thanks.
Opinions expressed by DZone contributors are their own.
Comments