@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.