Skip to content

Commit 1a7cf79

Browse files
authored
Merge pull request #151369 from dlepow/apimappsvc
[APIM] Update App Service tutorial
2 parents 62f7e4b + 9237283 commit 1a7cf79

12 files changed

+182
-96
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"redirect_url": "/previous-versions/azure/virtual-machines/linux/tutorial-govern-resources",
66
"redirect_document_id": false
77
},
8+
{
9+
"source_path": "articles/api-management/import-api-app-as-api.md",
10+
"redirect_url": "/azure/api-management/import-app-service-as-api",
11+
"redirect_document_id": false
12+
},
813
{
914
"source_path": "articles/virtual-machines/linux/copy-vm.md",
1015
"redirect_url": "/previous-versions/azure/virtual-machines/linux/copy-vm",

articles/api-management/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
href: import-soap-api.md
108108
- name: Import a SOAP API and convert to REST
109109
href: restify-soap-api.md
110-
- name: Import an API App
111-
href: import-api-app-as-api.md
110+
- name: Import a Web App
111+
href: import-app-service-as-api.md
112112
- name: Import a Function App
113113
href: import-function-app-as-api.md
114114
- name: Import a Logic App

articles/api-management/add-api-manually.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ description: This tutorial shows you how to use API Management (APIM) to add an
44
services: api-management
55
documentationcenter: ''
66
author: mikebudzynski
7-
manager: cfowler
8-
editor: ''
97

108
ms.service: api-management
11-
ms.workload: mobile
12-
ms.tgt_pltfrm: na
139
ms.topic: tutorial
14-
ms.date: 04/20/2020
10+
ms.date: 04/26/2021
1511
ms.author: apimpm
1612

1713
---
@@ -52,7 +48,7 @@ This section shows how to add a "/get" operation in order to map it to the back
5248

5349
1. Select the API you created in the previous step.
5450
2. Click **+ Add Operation**.
55-
3. In the **URL**, select **GET** and enter "*/get*" in the resource.
51+
3. In the **URL**, select **GET** and enter `/get` in the resource.
5652
4. Enter "*FetchData*" for **Display name**.
5753
5. Select **Save**.
5854

@@ -74,20 +70,44 @@ This section shows how to add an operation that takes a parameter. In this case,
7470

7571
1. Select the API you created in the previous step.
7672
2. Click **+ Add Operation**.
77-
3. In the **URL**, select **GET** and enter "*/status/{code}*" in the resource. Optionally, you can provide some information associated with this parameter. For example, enter "*Number*" for **TYPE**, "*200*" (default) for **VALUES**.
78-
4. Enter "GetStatus" for **Display name**.
73+
3. In the **URL**, select **GET** and enter `*/status/{code}` in the resource. Optionally, you can provide some information associated with this parameter. For example, enter "*Number*" for **TYPE**, "*200*" (default) for **VALUES**.
74+
4. Enter "WildcardGet" for **Display name**.
7975
5. Select **Save**.
8076

8177
### Test the operation
8278

8379
Test the operation in the Azure portal. Alternatively, you can test it in the **Developer portal**.
8480

8581
1. Select the **Test** tab.
86-
2. Select **GetStatus**. By default the code value is set to "*200*". You can change it to test other values. For example, type "*418*".
82+
2. Select **WildcardGet**. By default the code value is set to "*200*". You can change it to test other values. For example, type "*418*".
8783
3. Press **Send**.
8884

8985
The response that the "http://httpbin.org/status/200" operation generates appears. If you want to transform your operations, see [Transform and protect your API](transform-api.md).
9086

87+
## Add and test a wildcard operation
88+
89+
This section shows how to add a wildcard operation. A wildcard operation lets you pass an arbitrary value with an API request. Instead of creating separate GET operations as shown in the previous sections, you could create a wildcard GET operation.
90+
91+
### Add the operation
92+
93+
1. Select the API you created in the previous step.
94+
2. Click **+ Add Operation**.
95+
3. In the **URL**, select **GET** and enter `/*` in the resource.
96+
4. Enter "*WildcardGet*" for **Display name**.
97+
5. Select **Save**.
98+
99+
### Test the operation
100+
101+
Test the operation in the Azure portal. Alternatively, you can test it in the **Developer portal**.
102+
103+
1. Select the **Test** tab.
104+
2. Select **WildcardGet**. Try one or more of the GET operations that you tested in previous sections, or try a different supported GET operation.
105+
106+
For example, in **Template parameters**, update the value next to the wildcard (*) name to `headers`. The operation returns the incoming request's HTTP headers.
107+
1. Press **Send**.
108+
109+
The response that the "http://httpbin.org/headers" operation generates appears. If you want to transform your operations, see [Transform and protect your API](transform-api.md).
110+
91111
[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-append-apis.md)]
92112

93113
[!INCLUDE [api-management-define-api-topics.md](../../includes/api-management-define-api-topics.md)]

articles/api-management/api-management-api-import-restrictions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ If you're receiving errors importing your OpenAPI document, make sure you've val
5454

5555
### <a name="open-import-export-general"> </a>General
5656

57-
- API definitions exported from API Management service are primarily intended for applications external to API Management service that need to call the API hosted in API Management service. Exported API definitions are not intended to be imported again into the same or different API Management service. For configuration management of API defiitions across different serivces/envionments, please refer to documentation regarding using API Management Service with Git.
57+
- API definitions exported from API Management service are primarily intended for applications external to API Management service that need to call the API hosted in API Management service. Exported API definitions are not intended to be imported again into the same or different API Management service. For configuration management of API definitions across different services/environments, please refer to documentation regarding using API Management Service with Git.
5858

5959
### Add new API via OpenAPI import
6060

articles/api-management/import-api-app-as-api.md

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
title: Import Azure Web App to Azure API Management | Microsoft Docs
3+
description: This article shows you how to use Azure API Management to import a web API hosted in Azure App Service.
4+
services: api-management
5+
documentationcenter: ''
6+
author: vladvino
7+
8+
ms.service: api-management
9+
ms.topic: article
10+
ms.date: 04/27/2021
11+
ms.author: apimpm
12+
13+
---
14+
# Import an Azure Web App as an API
15+
16+
This article shows how to import an Azure Web App to Azure API Management and test the imported API, using the Azure portal.
17+
18+
> [!NOTE]
19+
> You can use the API Management Extension for Visual Studio Code to import and manage your APIs. Follow the [API Management Extension tutorial](visual-studio-code-tutorial.md) to install and get started.
20+
21+
In this article, you learn how to:
22+
23+
> [!div class="checklist"]
24+
> * Import a Web App hosted in App Service
25+
> * Test the API in the Azure portal
26+
27+
## Expose Web App with API Management
28+
29+
[Azure App Service](../app-service/overview.md) is an HTTP-based service for hosting web applications, REST APIs, and mobile backends. API developers can use their preferred technology stacks and pipelines to develop APIs and publish their API backends as Web Apps in a secure, scalable environment. Then, use API Management to expose the Web Apps, manage and protect the APIs throughout their lifecycle, and publish them to consumers.
30+
31+
API Management is the recommended environment to expose a Web App-hosted API, for several reasons:
32+
33+
* Decouple managing and securing the front end exposed to API consumers from managing and monitoring the backend Web App
34+
* Manage web APIs hosted as Web Apps in the same environment as your other APIs
35+
* Apply [policies](api-management-policies.md) to change API behavior, such as call rate limiting
36+
* Direct API consumers to API Management's customizable [developer portal](api-management-howto-developer-portal.md) to discover and learn about your APIs, request access, and try them
37+
38+
For more information, see [About API Management](api-management-key-concepts.md).
39+
40+
## OpenAPI specification versus wildcard operations
41+
42+
API Management supports import of Web Apps hosted in App Service that include an OpenAPI specification (Swagger definition). However, an OpenAPI specification isn't required.
43+
44+
* If the Web App has an OpenAPI specification configured in an API definition, API Management creates API operations that map directly to the definition, including required paths, parameters, and response types.
45+
46+
Having an OpenAPI specification is recommended, because the API is imported to API Management with high fidelity, giving you flexibility to validate, manage, secure, and update configurations for each operation separately.
47+
48+
* If an OpenAPI specification isn't provided, API Management generates [wildcard operations](add-api-manually.md#add-and-test-a-wildcard-operation) for the common HTTP verbs (GET, PUT, and so on). Append a required path or parameters to a wildcard operation to pass an API request through to the backend API.
49+
50+
With wildcard operations, you can still take advantage of the same API Management features, but operations aren't defined at the same level of detail by default. In either case, you can [edit](edit-api.md) or [add](add-api-manually.md) operations to the imported API.
51+
52+
### Example
53+
Your backend Web App might support two GET operations:
54+
* `https://myappservice.azurewebsites.net/customer/{id}`
55+
* `https://myappservice.azurewebsites.net/customers`
56+
57+
You import the Web App to your API Management service at a path such as `https://contosoapi.azureapi.net/store`. The following table shows the operations that are imported to API Management, either with or without an OpenAPI specification:
58+
59+
| Type |Imported operations |Sample requests |
60+
|---------|---------|---------|
61+
|OpenAPI specification | `GET /customer/{id}`<br/><br/> `GET /customers` | `GET https://contosoapi.azureapi.net/store/customer/1`<br/><br/>`GET https://contosoapi.azureapi.net/store/customers` |
62+
|Wildcard | `GET /*` | `GET https://contosoapi.azureapi.net/store/customer/1`<br/><br/>`GET https://contosoapi.azureapi.net/store/customers` |
63+
64+
The wildcard operation allows the same requests to the backend service as the operations in the OpenAPI specification. However, the OpenAPI-specified operations can be managed separately in API Management.
65+
66+
## Prerequisites
67+
68+
+ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md).
69+
+ Make sure there is an App Service in your subscription. For more information, see [App Service documentation](../app-service/index.yml).
70+
71+
For steps to create an example web API and publish as an Azure Web App, see:
72+
73+
* [Tutorial: Create a web API with ASP.NET Core](/aspnet/core/tutorials/first-web-api)
74+
* [Publish an ASP.NET Core app to Azure with Visual Studio Code](/aspnet/core/tutorials/publish-to-azure-webapp-using-vscode)
75+
76+
[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-navigate-to-instance.md)]
77+
78+
## <a name="create-api"> </a>Import and publish a backend API
79+
80+
> [!TIP]
81+
> The following steps start the import by using Azure API Management in the Azure portal. You can also link to API Management directly from your Web App, by selecting **API Management** from the app's **API** menu.
82+
83+
1. Navigate to your API Management service in the Azure portal and select **APIs** from the menu.
84+
1. Select **App Service** from the list.
85+
86+
:::image type="content" source="media/import-app-service-as-api/app-service.png" alt-text="Create from App Service":::
87+
1. Select **Browse** to see the list of App Services in your subscription.
88+
1. Select an App Service. If an OpenAPI definition is associated with the selected Web App, API Management fetches it and imports it.
89+
90+
If an OpenAPI definition isn't found, API Management exposes the API by generating wildcard operations for common HTTP verbs.
91+
1. Add an API URL suffix. The suffix is a name that identifies this specific API in this API Management instance. It has to be unique in this APIM instance.
92+
1. Publish the API by associating the API with a product. In this case, the "*Unlimited*" product is used. If you want the API to be published and be available to developers, add it to a product. You can do it during API creation or set it later.
93+
94+
> [!NOTE]
95+
> Products are associations of one or more APIs. You can include many APIs and offer them to developers through the developer portal. Developers must first subscribe to a product to get access to the API. When they subscribe, they get a subscription key that is good for any API in that product. If you created the APIM instance, you are an administrator already, so you are subscribed to every product by default.
96+
>
97+
> By default, each API Management instance comes with two sample products:
98+
> * **Starter**
99+
> * **Unlimited**
100+
1. Enter other API settings. You can set the values during creation or configure them later by going to the **Settings** tab. The settings are explained in the [Import and publish your first API](import-and-publish.md#import-and-publish-a-backend-api) tutorial.
101+
1. Select **Create**.
102+
:::image type="content" source="media/import-app-service-as-api/import-app-service.png" alt-text="Create API from App Service":::
103+
104+
## Test the new API in the Azure portal
105+
106+
Operations can be called directly from the Azure portal, which provides a convenient way to view and test the operations of an API. You can also test the API in the [developer portal](api-management-howto-developer-portal.md) or using your own REST client tools.
107+
108+
1. Select the API you created in the previous step.
109+
1. Select the **Test** tab.
110+
1. Select an operation.
111+
112+
The page displays fields for query parameters and fields for the headers. One of the headers is "Ocp-Apim-Subscription-Key", for the subscription key of the product that is associated with this API. If you created the API Management instance, you are an administrator already, so the key is filled in automatically.
113+
1. Press **Send**.
114+
115+
When the test is successful, the backend responds with **200 OK** and some data.
116+
117+
### Test wildcard operation in the portal
118+
119+
When wildcard operations are generated, the operations might not map directly to the backend API. For example, a wildcard GET operation imported in API Management uses the path `/` by default. However, your backend API might support a GET operation at the following path:
120+
121+
`/api/TodoItems`
122+
123+
You can test the path `/api/TodoItems` as follows.
124+
125+
1. Select the API you created, and select the operation.
126+
1. Select the **Test** tab.
127+
1. In **Template parameters**, update the value next to the wildcard (*) name. For example, enter `api/TodoItems`. This value gets appended to the path `/` for the wildcard operation.
128+
129+
:::image type="content" source="media/import-app-service-as-api/test-wildcard-operation.png" alt-text="Test wildcard operation":::
130+
1. Select **Send**.
131+
132+
[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-append-apis.md)]
133+
134+
[!INCLUDE [api-management-define-api-topics.md](../../includes/api-management-define-api-topics.md)]
135+
136+
## Next steps
137+
138+
> [!div class="nextstepaction"]
139+
> [Transform and protect a published API](transform-api.md)
Binary file not shown.
9.71 KB
Loading
46.8 KB
Loading
62 KB
Loading

0 commit comments

Comments
 (0)