|
1 | 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. |
| 2 | +title: Import an Azure web app to Azure API Management | Microsoft Docs |
| 3 | +description: Learn how to use Azure API Management to import a web API that's hosted in Azure App Service. |
4 | 4 | services: api-management
|
5 | 5 | author: dlepow
|
6 | 6 |
|
7 | 7 | ms.service: azure-api-management
|
8 | 8 | ms.topic: how-to
|
9 |
| -ms.date: 04/27/2021 |
| 9 | +ms.date: 03/28/2025 |
10 | 10 | ms.author: danlep
|
11 | 11 |
|
| 12 | +#customer intent: As an API developer, I want to import a web app as an API to API Management so that I can take advantage of the benefits of using this environment. |
12 | 13 | ---
|
13 |
| -# Import an Azure Web App as an API |
| 14 | +# Import an Azure web app as an API |
14 | 15 |
|
15 | 16 | [!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
|
16 | 17 |
|
17 |
| -This article shows how to import an Azure Web App to Azure API Management and test the imported API, using the Azure portal. |
| 18 | +This article shows how to use the Azure portal to import an Azure web app as an API to Azure API Management and test the imported API. |
18 | 19 |
|
19 | 20 | [!INCLUDE [api-management-workspace-availability](../../includes/api-management-workspace-availability.md)]
|
20 | 21 |
|
21 | 22 | In this article, you learn how to:
|
22 | 23 |
|
23 | 24 | > [!div class="checklist"]
|
24 |
| -> * Import a Web App hosted in App Service |
| 25 | +> * Import a web app, which is hosted in Azure App Service, as an API |
25 | 26 | > * Test the API in the Azure portal
|
26 | 27 |
|
27 |
| -## Expose Web App with API Management |
| 28 | +## Expose a web app by using API Management |
28 | 29 |
|
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 | +[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. They can then use API Management to expose the web apps, manage and protect the APIs throughout their lifecycle, and publish them to consumers. |
30 | 31 |
|
31 |
| -API Management is the recommended environment to expose a Web App-hosted API, for several reasons: |
| 32 | +Using API Management to expose a Web Apps-hosted API provides these benefits: |
32 | 33 |
|
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 |
| 34 | +* Decouple managing and securing the front end that's exposed to API consumers from managing and monitoring the backend web app. |
| 35 | +* Manage web APIs hosted as web apps in the same environment as your other APIs. |
| 36 | +* Apply [policies](api-management-policies.md) to change API behavior, such as call-rate limiting. |
| 37 | +* Direct API consumers to the customizable API Management [developer portal](api-management-howto-developer-portal.md) so they can discover and learn about your APIs, request access, and try APIs. |
37 | 38 |
|
38 | 39 | For more information, see [About API Management](api-management-key-concepts.md).
|
39 | 40 |
|
40 |
| -## OpenAPI definition versus wildcard operations |
| 41 | +## OpenAPI definition vs. wildcard operations |
41 | 42 |
|
42 |
| -API Management supports import of Web Apps hosted in App Service that include an OpenAPI definition (Swagger definition). However, an OpenAPI definition isn't required. |
| 43 | +API Management supports import of web apps hosted in App Service that include an OpenAPI definition (a Swagger definition). However, an OpenAPI definition isn't required. |
43 | 44 |
|
44 |
| -* If the Web App is configured with an OpenAPI definition, API Management will detect that. Alternatively, you can [manually import the definition](import-api-from-oas.md) to API Management. API Management then creates API operations that map directly to the definition, including required paths, parameters, and response types. |
| 45 | +* If the web app is configured with an OpenAPI definition, API Management will detect that. Alternatively, you can [manually import the definition](import-api-from-oas.md) to API Management. API Management then creates API operations that map directly to the definition, including required paths, parameters, and response types. |
45 | 46 |
|
46 |
| - Having an OpenAPI definition 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 | + Having an OpenAPI definition is recommended, because the API is imported to API Management with high fidelity, giving you the flexibility to validate, manage, secure, and update configurations for each operation separately. |
47 | 48 |
|
48 | 49 | * If an OpenAPI definition 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 |
|
50 | 51 | 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 |
|
52 | 53 | ### 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 | 54 |
|
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: |
| 55 | +Your backend web app might support two GET operations: |
| 56 | +* `https://<app-service>.azurewebsites.net/customer/{id}` |
| 57 | +* `https://<app-service>.azurewebsites.net/customers` |
| 58 | + |
| 59 | +You import the web app to your API Management service at a path like `https://<api>.azureapi.net/store`. The following table shows the operations that are imported to API Management, with or without an OpenAPI specification: |
58 | 60 |
|
59 | 61 | | Type |Imported operations |Sample requests |
|
60 | 62 | |---------|---------|---------|
|
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 | +|OpenAPI specification | `GET /customer/{id}`<br/><br/> `GET /customers` | `GET https://<api>.azureapi.net/store/customer/1`<br/><br/>`GET https://<api>.azureapi.net/store/customers` | |
| 64 | +|Wildcard | `GET /*` | `GET https://<api>.azureapi.net/store/customer/1`<br/><br/>`GET https://<api>.azureapi.net/store/customers` | |
63 | 65 |
|
64 | 66 | 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 | 67 |
|
66 | 68 | ## Prerequisites
|
67 | 69 |
|
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: |
| 70 | ++ Complete the quickstart [Create an Azure API Management instance](get-started-create-service-instance.md). |
| 71 | ++ Make sure there's an app service in your subscription. For more information, see [App Service documentation](../app-service/index.yml). |
72 | 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) |
| 73 | + For information about creating an example web API and publishing it as an Azure web app, see: |
75 | 74 |
|
76 |
| -[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-navigate-to-instance.md)] |
| 75 | + * [Tutorial: Create a web API with ASP.NET Core](/aspnet/core/tutorials/first-web-api). |
| 76 | + * [Publish an ASP.NET Core app to Azure with Visual Studio Code](/aspnet/core/tutorials/publish-to-azure-webapp-using-vscode). |
77 | 77 |
|
78 |
| -## <a name="create-api"> </a>Import and publish a backend API |
| 78 | +## Import and publish a backend API |
79 | 79 |
|
80 | 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. |
| 81 | +> In the following steps, you start the import by using API Management in the Azure portal. You can also link to API Management directly from your web app by selecting **API Management** in the app's **API** menu. |
| 82 | +
|
| 83 | +1. Navigate to your API Management service in the [Azure portal](https://portal.azure.com). |
| 84 | +1. In the left menu, in the **APIs section**, select **APIs**, and then select **+ Add API**. |
| 85 | +1. Select the **App Service** tile: |
82 | 86 |
|
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. |
| 87 | + :::image type="content" source="media/import-app-service-as-api/app-service.png" alt-text="Screeenshot that shows the App Service tile."::: |
85 | 88 |
|
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 | +1. Select **Browse** to see the list of app services in your subscription. |
| 90 | +1. Select an app service and then click the **Select** button. If an OpenAPI definition is associated with the selected web app, API Management fetches it and imports it. |
89 | 91 |
|
90 | 92 | 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 | +1. Add an **API URL suffix**. The suffix is a name that identifies the API in the API Management instance. It has to be unique in the API Management instance. |
| 94 | +1. If you want the API to be published and available to developers, switch to the **Full** view and associate the API with a **Product**. This example uses the **Unlimited** product. (You can add your API to a product when you create it or later via the **Settings** tab.) |
93 | 95 |
|
94 | 96 | > [!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. |
| 97 | + > Products are associations of one or more APIs offered to developers via the developer portal. First, developers must subscribe to a product to get access to the API. After they subscribe, they get a subscription key for any API in the product. As creator of the API Management instance, you're an administrator and are subscribed to every product by default. |
96 | 98 | >
|
97 |
| - > By default, each API Management instance comes with two sample products: |
| 99 | + > In certain tiers, each API Management instance comes with two default sample products: |
98 | 100 | > * **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 | + > * **Unlimited** |
| 102 | +
|
| 103 | +1. Enter other API settings. You can set these values when you create the API 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. |
| 104 | + |
101 | 105 | 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"::: |
| 106 | + :::image type="content" source="media/import-app-service-as-api/import-app-service.png" alt-text="Screenshot that shows the Create from App Service window." lightbox="media/import-app-service-as-api/import-app-service.png"::: |
103 | 107 |
|
104 | 108 | ## Test the new API in the Azure portal
|
105 | 109 |
|
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. |
| 110 | +You can call operations directly from the Azure portal. This method 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 by using your own REST client tools. |
107 | 111 |
|
108 | 112 | 1. Select the API you created in the previous step.
|
109 |
| -1. Select the **Test** tab. |
110 |
| -1. Select an operation. |
| 113 | +1. On the **Test** tab, select an operation. |
| 114 | + |
| 115 | + The page displays fields for query parameters and fields for the headers. One of the headers is `Ocp-Apim-Subscription-Key`. This header is for the subscription key of the product that's associated with the API. If you created the API Management instance, you're an administrator already, so the key is filled in automatically. |
111 | 116 |
|
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 | 117 | 1. Press **Send**.
|
114 | 118 |
|
115 | 119 | When the test is successful, the backend responds with **200 OK** and some data.
|
116 | 120 |
|
117 |
| -### Test wildcard operation in the portal |
| 121 | +### Test a wildcard operation in the portal |
118 | 122 |
|
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: |
| 123 | +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 path `/api/todoItems`. |
120 | 124 |
|
121 |
| -`/api/TodoItems` |
| 125 | +To test the path `/api/todoItems`: |
122 | 126 |
|
123 |
| -You can test the path `/api/TodoItems` as follows. |
| 127 | +1. Select the API that you created, and then select an operation. |
| 128 | +1. On the **Test** tab, under **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. |
124 | 129 |
|
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. |
| 130 | + :::image type="content" source="media/import-app-service-as-api/test-wildcard-operation.png" alt-text="Screenshot that shows the steps for testing an operation." lightbox="media/import-app-service-as-api/test-wildcard-operation.png"::: |
128 | 131 |
|
129 |
| - :::image type="content" source="media/import-app-service-as-api/test-wildcard-operation.png" alt-text="Test wildcard operation"::: |
130 | 132 | 1. Select **Send**.
|
131 | 133 |
|
132 | 134 | [!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-append-apis.md)]
|
|
0 commit comments