Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
APPLIES TO: All API Management tiers
Backend APIs are imported into an API Management (APIM) API or created and managed manually. The steps in this tutorial, show you how to:
This method lets developers continue with the implementation and testing of the API Management instance even if the backend isn't available to send real responses.
Tip
API teams can use this feature in workspaces. Workspaces provide isolated administrative access to APIs and their own API runtime environments.
The ability to mock up responses is useful in many scenarios:
In this tutorial, you learn how to:
The steps in this section show how to create an HTTP API with no backend.
Sign in to the Azure portal, and then navigate to your API Management instance.
Select APIs > + Add API > HTTP tile.
In the Create an HTTP API window, select Full.
Enter Test API for Display name.
Select Unlimited for Products.
Ensure that Managed is selected for Gateways.
Select Create.
An API exposes one or more operations. In this section, you'll add an operation to the HTTP API you created. Calling the operation after completing the steps in this section triggers an error. After you complete the steps in the Enable response mocking section, you'll get no errors.
Select the API you created in the previous step.
Select + Add Operation.
In the Frontend window, enter the following values.
Setting | Value | Description |
---|---|---|
Display name | Test call | The name that is displayed in the developer portal. |
URL (HTTP verb) | GET | Select one of the predefined HTTP verbs. |
URL | /test | A URL path for the API. |
Description | Optional description of the operation, used to provide documentation in the developer portal to the developers using this API. |
Select the Responses tab, located under the URL, Display name, and Description fields. Enter settings on this tab to define response status codes, content types, examples, and schemas.
Select + Add response, and select 200 OK from the list.
Under the Representations heading on the right, select + Add representation.
Enter application/json into the search box and select the application/json content type.
In the Sample text box, enter { "sampleField" : "test" }
.
Select Save.
Although not required for this example, you can configure more settings for an API operation on other tabs, including:
Tab | Description |
---|---|
Query | Add query parameters. Besides providing a name and description, you can also provide values that are assigned to a query parameter. You can mark one of the values as default (optional). |
Request | Define request content types, examples, and schemas. |
Select the API you created in Create a test API.
In the window on the right, ensure that the Design tab is selected.
Select the test operation that you added.
In the Inbound processing window, select + Add policy.
Select Mock responses from the gallery.
In the API Management response textbox, type 200 OK, application/json. This selection indicates that your API should return the response sample you defined in the previous section.
Select Save.
Tip
A yellow bar with the text Mocking is enabled displays. This indicates that the responses returned from API Management are mocked by the mocking policy and aren't produced by the backend.
Select the API you created in Create a test API.
Select the Test tab.
Ensure that the Test call API is selected, and then select Send to make a test call.
The HTTP response displays the JSON provided as a sample in the first section of the tutorial.
In this tutorial, you learned how to:
Advance to the next tutorial:
Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Explore API Management - Training
Learn how the API Management service functions, how to transform and secure APIs, and how to create a backend API.
Certification
Microsoft Certified: Azure Cosmos DB Developer Specialty - Certifications
Write efficient queries, create indexing policies, manage, and provision resources in the SQL API and SDK with Microsoft Azure Cosmos DB.