Blog

How to Mock API Response in Azure API Management?

Introduction

Mocking provides a way for APIs to return sample response even when their backend is under development.

This enables app developers to proceed with implementation and testing and can be useful in many scenarios:

·       When the API façade is designed first, and the backend implementation comes later or is worked upon in parallel

·       When the backend is temporarily not operational or not able to scale

Scenario

mock api response

In one of our recent BizTalk HL7 project, where we are loading the EDI 837 claims to SQL data ware house of a health care medical group as shown in the above diagram.

Once data is loaded to DW database, there are bunch of SSIS packages which runs to populate different kind of jobs and reports. These data are also used by operation department through internal web application. So, IT team raised a requirement for REST API to access patient details and claim data in their web app. The dotted box in the above diagram is the requirement.

Since we already have BizTalk middleware in place we decided to develop a BizTalk interface to pull the data and publish it as a REST API.

Database team did not want to give direct access to their table so they decide to create a view as per our requirement which BizTalk would have access to.

Now till we develop this API, front end team cannot proceed with implementation. They had dependency on BizTalk team. To get rid of this dependency, we thought of trying Mock Response in Azure API Management so that both the team can work parallelly on their respective implementation.

To begin, we had to come up with the following sample response.

Mock Response for a given memberId:

mock api response

Steps to create Mock Response in Azure Portal

1. Create a new Azure API Management service instance. In the Azure portal, select Create a resource > Enterprise Integration > API management.

mock api response

2.       Once your APIM service instance is created, select APIs from under API MANAGEMENT

mock api response

3.       Create a blank API 

mock api response

4.       Provide Display Name and select Unlimited Product and click on create.

mock api response

5.       Now add a new operation.

mock api response

6.       Provide Name, URL and Display Name. Click on Response tab as shown below

mock api response

7.       Click on Add response and select 200 OK. 

mock api response

8.       Select application/json as CONTENT TYPE under Representation as shown below.

mock api response

9.       Add the following JSON sample response in SAMPLE box as shown below. Then click Create

{

  “PatientId”: “ABC50920”,

  “MemberId”: “XYZ001”,

  “FirstName”: “RICHARD”,

  “LastName”: “CARDONE”,

  “DateOfBirth”: “09/20/1985”,

  “Gender”: “M”,

  “AddressLine1”: “2021 MORSE AVE”,

  “CityName”: “SAN LEANDRO”,

  “StateorProvinceCode”: “CA”,

  “ZipCode”: “95835”,

  “HealthPlan”: “BS”,

  “HealthPlanName”: “BLUE SHIELD OF CALIFORNIA”,

  “FullName”: “CARDONE,RICHARD “

}

mock api response

10.       Select the newly created operation (Member Detail) and then select the Form-based editor in Inbound processing as shown below.

mock api response

11.       Click on Mocking tab

mock api response

12.       Under Mocking tab, select Static response radio button. Then select 200 response as shown below.

mock api response

13. Click on Save

mock api response

14.       Now your mock response API is ready and it would look like as below. You can see the message “Mocking is enabled”

mock api response

Testing

Click on Test tab. Click on Send button.

mock api response

You should get the mock response as shown below.

mock api response

To test the API using postman, you need to copy the Request URL from the Test tab as shown below.

mock api response

You also need to provide the subscription key.

mock api response

Summary

API Management enables you to package and publish APIs to your internal developer team and external partner. You can build an API façade for your existing backend which can be managed and protected from misuse and abuse using API Management.

In this post we created a new API in the APIM and used it for the Mock response. Mocking can be very useful to return sample response even when their backend is under development.

This enables app developers to proceed with implementation and testing and can be useful in many scenarios:

·       When the API façade is designed first, and the backend implementation comes later or is worked upon in parallel

·       When the backend is temporarily not operational or not able to scale

Related Posts


VNB Consulting RPA AI Builder UI Flow

June 6, 2020

Power Automate Robotic Process Automation & AI builder – Part I

Power Automate a cloud-based service offered by Microsoft has been helping many organizations to create automated workflows between their favorite apps and services. Expanding the capabilities of Power Automate, Microsoft has come up with a new feature called UI Flow which helps to create a Robotic process Automation (RPA). With this new addition, Power Automate now also

vnb-blog-power-bi-arcgis

May 4, 2020

ArcGIS Maps With Power BI

ArcGIS by Esri is now a built-in feature in Power BI to provide enhanced mapping capabilities taking it beyond the presentation of points on a map to a whole new level. It enables to attach layers of demographic data to a map with ease. The combination of this location-based data layers on a map with