Managing multiple REST APIs in Azure API Management

3.3k views Asked by At

I am building REST APIs with MicroServices, which means I have different services for providing different resources. Suppose I have below services:

ServiceA is providing resources resourcesA and resourcesA1 with below URLs https://my-internal-endpoint-for-serviceA/resourcesA https://my-internal-endpoint-for-serviceA/resourcesA1

ServiceB is providing resources resourcesB and resourcesB1 with below URLs https://my-internal-endpoint-for-serviceB/resourcesB https://my-internal-endpoint-for-serviceB/resourcesB1

Now, I want to manage them in Azure API Management. To publish them (by importing the Swagger document from services), API Management portal need an API path for publishing. So, serviceA and serviceB can be published as below: https://my-api-azure-api.net/serviceA/resourcesA https://my-api-azure-api.net/serviceA/resourcesA1 https://my-api-azure-api.net/serviceB/resourcesB https://my-api-azure-api.net/serviceB/resourcesB1

But to be more resources based API management, I am expecting the published APIs to be more like below: https://my-api-azure-api.net/resourcesA https://my-api-azure-api.net/resourcesA1 https://my-api-azure-api.net/resourcesB https://my-api-azure-api.net/resourcesB1

Unfortunately, API management does not allow me for pubshing 2 APIs (serviceA and serviceB) to same path (root path in this case). I don't want to put the service name (or something equivalent) in the URL path as the service name is something duplication of the resource name provided by it. How do I workaround this?

2

There are 2 answers

2
Alex01 On

The Azure API Management Policies can help you here, in particular the control flow with the ability to forward requests. The documentation is here: https://learn.microsoft.com/en-us/azure/api-management/api-management-policy-reference

I would approach this by setting up the resources as a single API, by adding one via swagger and then adding in the other services to this one to make it complete (as you want it to appear as a single complete service). Once this is in place you are then free to apply the policies.

Note: you may have to expand the resource path in the following way

https://my-api-azure-api.net/mynewservice/resourcesA
https://my-api-azure-api.net/mynewservice/resourcesA1
https://my-api-azure-api.net/mynewservice/resourcesB
https://my-api-azure-api.net/mynewservice/resourcesB1
0
Andreas L On

Maybe the answer to this question can help: How to chain APIs using Azure API management

You can use the same policy to map several operations of the same API in API Management to different backend APIs. But in general all APIs are exposed as <myGateway>.azure-api.net/<myApi>/<myOperation>.