You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/api-management/visual-studio-code-tutorial.md
+30-25Lines changed: 30 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.service: azure-api-management
5
5
author: dlepow
6
6
ms.author: danlep
7
7
ms.topic: tutorial
8
-
ms.date: 10/17/2023
8
+
ms.date: 11/12/2024
9
9
ms.custom: devdivchpfy22
10
10
---
11
11
@@ -35,16 +35,16 @@ For an introduction to more API Management features, see the API Management tuto
35
35
36
36
## Import an API
37
37
38
-
The following example imports an OpenAPI Specification in JSON format into API Management. Microsoft provides the backend API used in this example, and hosts it on Azure at `https://conferenceapi.azurewebsites.net`.
38
+
The following example imports an OpenAPI Specification in JSON format into API Management. For this example, you import the open source [Petstore API](https://petstore.swagger.io/).
39
39
40
40
1. In Visual Studio Code, select the Azure icon from the Activity Bar.
41
41
1. In the Explorer pane, expand the API Management instance you created.
42
42
1. Right-click **APIs**, and select **Import from OpenAPI Link**.
43
43
1. When prompted, enter the following values:
44
-
1. An **OpenAPI link** for content in JSON format. For this example: `https://conferenceapi.azurewebsites.net?format=json`.
44
+
1. An **OpenAPI link** for content in JSON format. For this example: `https://petstore.swagger.io/v2/swagger.json`.
45
45
46
-
This file specifies the backend service that implements the example API, in this case `https://conferenceapi.azurewebsites.net`. API Management forwards requests to this web service.
47
-
1. An **API name**, such as *demo-conference-api*, that is unique in the API Management instance. This name can contain only letters, number, and hyphens. The first and last characters must be alphanumeric. This name is used in the path to call the API.
46
+
This file specifies the backend service that implements the example API and the operations it supports.
47
+
1. An **API name**, such as *petstore*, that is unique in the API Management instance. This name can contain only letters, number, and hyphens. The first and last characters must be alphanumeric. This name is used in the path to call the API.
48
48
49
49
After the API is imported successfully, it appears in the Explorer pane, and available API operations appear under the **Operations** node.
50
50
@@ -66,24 +66,28 @@ This section shows how to apply common outbound policies to your API that transf
66
66
67
67
1. In the Explorer pane, select **Policy** under the *demo-conference-api* that you imported. The policy file opens in the editor window. This file configures policies for all operations in the API.
68
68
69
-
1. Update the file with the following content in the `<outbound>` element:
* The first `set-header` policy adds a custom response header for demonstration purposes.
84
-
* The second `set-header` policy deletes the **X-Powered-By** header, if it exists. This header can reveal the application framework used in the API backend, and publishers often remove it.
85
-
* The `redirect-content-urls` policy rewrites (masks) links in the response body so that they point to the equivalent links via the API Management gateway.
86
-
88
+
* The `rate-limit` policy in the `inbound` section limits the number of calls to the API to 3 every 15 seconds.
89
+
* The `set-header` policy in the `outbound` section adds a custom response header for demonstration purposes.
90
+
87
91
1. Save the file. If you're prompted, select **Upload** to upload the file to the cloud.
88
92
89
93
## Test the API
@@ -104,8 +108,9 @@ You need a subscription key for your API Management instance to test the importe
104
108
105
109
### Test an API operation
106
110
107
-
1. In the Explorer pane, expand the **Operations** node under the *demo-conference-api* that you imported.
108
-
1. Select an operation such as *GetSpeakers*, and then right-click the operation and select **Test Operation**.
111
+
1. In the Explorer pane, expand the **Operations** node under the *petstore* that you imported.
112
+
1. Select an operation such as *[GET] Find pet by ID*, and then right-click the operation and select **Test Operation**.
113
+
1. In the editor window, substitute `5` for the `petId` parameter in the request URL.
109
114
1. In the editor window, next to **Ocp-Apim-Subscription-Key**, replace `{{SubscriptionKey}}` with the subscription key that you copied.
110
115
1. Select **Send request**.
111
116
@@ -115,11 +120,11 @@ When the request succeeds, the backend responds with **200 OK** and some data.
115
120
116
121
:::image type="content" source="media/visual-studio-code-tutorial/test-api-policies.png" alt-text="Screenshot of the API test response in Visual Studio Code.":::
117
122
118
-
Notice the following details in the response:
123
+
Notice the following detail in the response:
119
124
120
125
* The **Custom** header is added to the response.
121
-
* The **X-Powered-By** header doesn't appear in the response.
122
-
* URLs to the API backend are redirected to the API Management gateway, in this case `https://apim-hello-world.azure-api.net/demo-conference-api`.
126
+
127
+
Now test the rate limiting policy. Select **Send request** four times in a row. After sending the request four times, you get the `429 Too Many Requests` response.
0 commit comments