Creating a multi-tier solution by using services in Azure

Introduction: All my articles are compiled into simple steps with detailed screen shots and elaborative description. By following these steps even, a novice programmer should be able to replicate scenario. Please go through the steps and provide your valuable feedback to make my next articles more clearer and intent.

Note: I took help of various internet sources while researching this item. Credit goes to internet and Microsoft communities. This is one of the topics in Azure certification.

This is my 14th article on Azure.

Please follow below links for my previous Azure articles

Azure WebApps

Azure Logic App

Azure Event Grids

Azure SQL

Azure AD MSAL

Azure AD and User Management

Azure Key Vault With Logic App

Azure Key Vault With Data Factory

Accessing Azure Blob Containers

Working With Azure MSMQ

Key Vault & Secrets

Function App

Azure Work Loads using Images and Containers

Follow below mentioned 21 steps to manipulate incoming request and out going responses of an api using proxy of API management in azure.

 After completing this blog, you will be able to do

  • Create API management resource and integrate it with Azure web app
  • Define or add custom headers for API
  • Modify API response before sending it to client
  • Host web app in Docker container
  • Configure API as proxy for another azure service with header and payload manipulation

Sample Description: Create a web app and deploy using docker container. Define API proxy by using API management- add custom headers and manipulate the response format.

Step 1: Open Azure portal (https://portal.azure.com)

Step 2: Create a new web app. This time we are going to publish the web application using docket container. Please select values as highlighted In below image. Select Image source as docker hub and provide image tag as “kennethreitz/httpbin:latest”

Step 3: Access the web app you created and browse it.

Step 4: Now we will observer different parts of this web app. Expand Response formats section and click on Get/Xml button

Step 5: Click on Try it our button

Step 6: If you click on Execute button, it will load response body and headers of this particular web application. Please observe them.

Step 7: In next steps we are going to override these headers and response by using proxy tier which is nothing but API management

Step 8: Now go back to wee application > Properties blade and collect the value from URL. This value we will use in next steps.

Step 9: Now create a API management resource as shown below

Step 10: Now we are going to create an api in API management. While creating API in API management give the URL of Web application, we created in step 2. In this step we are binding web application with API management proxy

Access API Management we created in previous step. Click on API’s blade. Finally click on Blank API.

Step 11: Now we are going to define headers for API. Access the Blank API we created in previous step and click on Add Operation link. Create a header as mentioned below

Step 12: In this step, we are going to create In bound policy to include or append header for all incoming request. Inbound processing is nothing but processing incoming request. Now I am going to define a policy which process each incoming request and appends header defined in previous step.

Click on All operations> Inbound Processing Box> Add Policy Link

Step 13: Various policies are available. Search for Set headers policy and click on Set Header Link. Create policy as mentioned below.

Step 14: Now go to Echo Headers> Backend Box and click on edit.

Step 15: Update the service URL by appending headers to it. Select Override check box.

Step 16: Test echo headers and observe the response. Lot of headers have been added as part of the response.

Step 17: Till now we have seen how to modify incoming request and add headers to it. Now we will see how to manipulate the response from API before sending it to requestor

Click on Add new operation and add one as shown below

Step 18: Click on Operation we created in previous step and test it. Observe the result, Now out put should be in xml format.

Step 19: Now define out bound custom policy for get Legacy Data operation as shown below

Step 20: Before click on Save add below mentioned line in <outbound> section and hit click.

<xml-to-json kind=”direct” apply=”always” consider-accept-header=”false” />

Above line will converts API result in to json format

Step 21: Now again test Get Legacy Data and you will see results in Json format. Same request in step #18 gave results in XML format.

This is how we can update incoming requests and outgoing responses using proxy of API management.

Happy Coding!!!

One thought on “Creating a multi-tier solution by using services in Azure

Leave a comment