Azure APIM-Multi API configuration in APIM

2023-10-26T15:43:04.02+00:00

Hi Team,

we had an API'S in APIM like 1. username 2. username and password 3. exchange token 4. Access token

All the above API'S are existed in an APIM.

Now the requirement is we have to develop an API that consists of all the functionality of the above API.

We want to integrate all the existing API'S into a single API into a same APIM.

Is there a way to call the existing API from another API and use the functionality of the above API.

Please suggest me and let me know the options.

P.S. APIM(5 API'S) > APIM(SINGLE API) (APIM is same)

Thanks,

Simanchala

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,067 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 23,450 Reputation points Microsoft Employee
    2023-10-27T09:52:26.4+00:00

    @Simanchala M [External], Technology Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I understand that you have multiple APIs in Azure API Management (APIM) and you want to integrate them into a single API in the same APIM. You are looking for a way to call the existing APIs from another API and use their functionality.

    I am sharing 2 approaches using which you can achive your requirement:

    Approach 1:

    To achieve this, you can use the APIM policy expressions to call the existing APIs from the new API. You can use the send-request policy to send a request to the existing APIs and receive a response. You can then use the response to modify the request or response of the new API.

    Here are the high-level steps to achieve this:

    1.Create a new API in APIM.

    2.Add the send-request policy to the inbound or outbound policy of the new API.

    3.In the send-request policy, specify the URL of the existing API that you want to call.

    4.Specify the HTTP method, headers, and body of the request.

    5.Receive the response from the existing API.

    6.Modify the request or response of the new API based on the response from the existing API.

    7.You can repeat steps 2-6 for each existing API that you want to call from the new API.

    Here is an example of the send-request policy that you can use to call an existing API:

    <send-request mode="new" response-variable-name="responseVariableName">
        <set-url>https://your-existing-api-url.com</set-url>
        <set-method>GET</set-method>
        <set-header name="Content-Type" exists-action="override">
            <value>application/json</value>
        </set-header>
        <set-body>@(context.Request.Body.As<string>(preserveContent: true))</set-body>
    </send-request>
    

    In this example, the send-request policy sends a GET request to the URL https://your-existing-api-url.com with the Content-Type header set to application/json. The request body is set to the body of the incoming request to the new API. The response from the existing API is stored in the responseVariableName variable.

    **
    NOTE:** Please don't directly copy the above policy. It is a sample and given for understanding purpose only.

    You need to modify this policy to suit your requirements. You can find more information about the send-request policy and other APIM policies in the Azure documentation: https://docs.microsoft.com/en-us/azure/api-management/api-management-policy-reference

    Approach 2:

    Alternatively, you can also explore options to Use set-backend-service policy. This policy allows you to change the backend service for certain operations. You can use this policy to point different operations in your new API to different existing APIs. The same has been discussed here: https://stackoverflow.com/questions/41002723/how-to-chain-apis-using-azure-api-management

    Remember, it’s important to handle error scenarios and ensure that the APIs are called in the correct sequence. Also, consider the impact on performance and latency when chaining multiple API calls.

    Please note that these are general approaches and you might need to adjust them based on your specific requirements and the details of your existing APIs.

    Hope this helps.

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.