Manage synchronous calls to async using API Management

DevBuster007 176 Reputation points
2021-03-01T02:21:50.393+00:00

I am using API Management in my project to make REST API calls to external API's.
We have one requirement where:

  1. Client will call us synchronously and will wait for the response.
  2. Our layer/project takes this synchronous call and calls external API: Lets say CreditCheckAPI
  3. CreditCheckAPI only accepts asynchronous calls

How can i use API Management so that i can manage synchronous incoming calls with async calls. I have to respond to our caller synchronously.
Please help.

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,877 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
338 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,606 Reputation points Microsoft Employee
    2021-03-01T06:06:21.697+00:00

    @DevBuster007 You can leverage policies to achieve this and in fact, this sample covers this exact scenario. Here is the same policy for reference.

       <!-- The policy defined in this file demonstrates how to mask an asynchronous API endpoint as if it is an synchronous one. -->  
       <!-- This is useful when modernizing APIs but some clients that call the API cannot be updated to the new behavior. -->  
         
       <!-- API used for this example is an Azure Logic Apps (request/resposne), in which retruns HTTP 202 status code, -->  
       <!-- and location header to retrieve the terminal payload. Retry count and interval is fixed  in this example but can also be customized. -->  
         
       <policies>  
           <inbound>  
               <base />  
           </inbound>  
           <backend>  
               <forward-request />  
           </backend>  
           <outbound>  
               <base />  
               <retry condition="@(((IResponse)context.Variables["var"]).StatusCode == 202)" count="10" interval="30">  
                   <send-request mode="new" response-variable-name="var" ignore-error="false">  
                       <set-url>@(context.Response.Headers["location"][0])</set-url>  
                       <set-method>GET</set-method>  
                   </send-request>  
               </retry>  
               <return-response response-variable-name="var" />  
           </outbound>  
           <on-error>  
               <base />  
           </on-error>  
       </policies>