|
| 1 | +--- |
| 2 | +title: Import Azure Container 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 Container Apps. |
| 4 | +services: api-management |
| 5 | +documentationcenter: '' |
| 6 | +author: adrianhall |
| 7 | + |
| 8 | +ms.service: api-management |
| 9 | +ms.topic: article |
| 10 | +ms.date: 11/03/2021 |
| 11 | +ms.author: adhal |
| 12 | + |
| 13 | +--- |
| 14 | +# Import an Azure Container App as an API |
| 15 | + |
| 16 | +This article shows how to import an Azure Container App to Azure API Management and test the imported API using the Azure portal. In this article, you learn how to: |
| 17 | + |
| 18 | +> [!div class="checklist"] |
| 19 | +> * Import a Container App that exposes a Web API |
| 20 | +> * Test the API in the Azure portal |
| 21 | +
|
| 22 | +> [!NOTE] |
| 23 | +> Azure Container Apps are currently in preview. |
| 24 | +
|
| 25 | +## Expose Container App with API Management |
| 26 | + |
| 27 | +[Azure Container Apps](../container-apps/overview.md) allows you to deploy containerized apps without managing complex infrastructure. API developers can write code using their preferred programming language or framework, build microservices with full support for Distributed Application Runtime (Dapr), and scale based on HTTP traffic or other events. |
| 28 | + |
| 29 | +API Management is the recommended environment to expose a Container App hosted web API, for several reasons: |
| 30 | + |
| 31 | +* Decouple managing and securing the front end exposed to API consumers from managing and monitoring the backend web API |
| 32 | +* Manage web APIs hosted as Container Apps in the same environment as your other APIs |
| 33 | +* Apply [policies](api-management-policies.md) to change API behavior, such as call rate limiting |
| 34 | +* 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 |
| 35 | + |
| 36 | +For more information, see [About API Management](api-management-key-concepts.md). |
| 37 | + |
| 38 | +## OpenAPI specification versus wildcard operations |
| 39 | + |
| 40 | +API Management supports import of Container Apps that provide an OpenAPI specification (Swagger definition). However, an OpenAPI specification isn't required. We recommend providing an OpenAPI specification. API Management can import individual operations, allowing you to validate, manage, secure, and update configurations for each operation separately. |
| 41 | + |
| 42 | +If the Container App exposes an OpenAPI specification, API Management creates API operations that map directly to the definition. API Management will look in several locations for an OpenAPI Specification |
| 43 | + |
| 44 | +* The Container App configuration. |
| 45 | +* `/openapi.json` |
| 46 | +* `/openapi.yml` |
| 47 | +* `/swagger/v1/swagger.json` |
| 48 | + |
| 49 | +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). You can still take advantage of the same API Management features, but operations aren't defined at the same level of detail. |
| 50 | + |
| 51 | +In either case, you can [edit](edit-api.md) or [add](add-api-manually.md) operations to the API after import. |
| 52 | + |
| 53 | +### Example |
| 54 | + |
| 55 | +Your backend Container App might support two GET operations: |
| 56 | + |
| 57 | +* `https://myappservice.azurewebsites.net/customer/{id}` |
| 58 | +* `https://myappservice.azurewebsites.net/customers` |
| 59 | + |
| 60 | +You import the Container App to your API Management service at a path such as `https://contosoapi.azure-api.net/store`. The following table shows the operations that are imported to API Management, either with or without an OpenAPI specification: |
| 61 | + |
| 62 | +| Type |Imported operations |Sample requests | |
| 63 | +|---------|---------|---------| |
| 64 | +|OpenAPI specification | `GET /customer/{id}`<br/><br/> `GET /customers` | `GET https://contosoapi.azure-api.net/store/customer/1`<br/><br/>`GET https://contosoapi.azure-api.net/store/customers` | |
| 65 | +|Wildcard | `GET /*` | `GET https://contosoapi.azure-api.net/store/customer/1`<br/><br/>`GET https://contosoapi.azure-api.net/store/customers` | |
| 66 | + |
| 67 | +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. |
| 68 | + |
| 69 | +## Prerequisites |
| 70 | + |
| 71 | ++ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md). |
| 72 | ++ Make sure there's a Container App that exposes a Web API in your subscription. For more information, see [Container Apps documentation](../container-apps/index.yml). |
| 73 | + |
| 74 | +[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-navigate-to-instance.md)] |
| 75 | + |
| 76 | +## <a name="create-api"> </a>Import and publish a backend API |
| 77 | + |
| 78 | +1. Navigate to your API Management service in the Azure portal and select **APIs** from the menu. |
| 79 | +2. Select **Container App** from the list. |
| 80 | + |
| 81 | + :::image type="content" source="media/import-container-app-with-oas/add-api.png" alt-text="Create from Container App"::: |
| 82 | + |
| 83 | +3. Select **Browse** to see the list of Container Apps in your subscription. |
| 84 | +4. Select a Container App. If an OpenAPI definition is associated with the selected Container App, API Management fetches it and imports it. If an OpenAPI definition isn't found, API Management exposes the API by generating wildcard operations for common HTTP verbs. |
| 85 | +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 API Management instance. |
| 86 | +2. 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. |
| 87 | + |
| 88 | + > [!NOTE] |
| 89 | + > 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 API Management instance, you're an administrator and subscribed to every product by default. |
| 90 | + > |
| 91 | + > Each API Management instance comes with two sample products when createdgg: |
| 92 | + > * **Starter** |
| 93 | + > * **Unlimited** |
| 94 | +
|
| 95 | +3. 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. |
| 96 | +4. Select **Create**. |
| 97 | + |
| 98 | + :::image type="content" source="media/import-container-app-with-oas/import-container-app.png" alt-text="Create API from Container App"::: |
| 99 | + |
| 100 | +## Test the new API in the Azure portal |
| 101 | + |
| 102 | +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. |
| 103 | + |
| 104 | +1. Select the API you created in the previous step. |
| 105 | +1. Select the **Test** tab. |
| 106 | +1. Select an operation. |
| 107 | + |
| 108 | + 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. |
| 109 | + |
| 110 | +1. Press **Send**. |
| 111 | + |
| 112 | + When the test is successful, the backend responds with **200 OK** and some data. |
| 113 | + |
| 114 | +### Test wildcard operation in the portal |
| 115 | + |
| 116 | +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: |
| 117 | + |
| 118 | +`/api/TodoItems` |
| 119 | + |
| 120 | +You can test the path `/api/TodoItems` as follows. |
| 121 | + |
| 122 | +1. Select the API you created, and select the operation. |
| 123 | +1. Select the **Test** tab. |
| 124 | +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. |
| 125 | + |
| 126 | + :::image type="content" source="media/import-container-app-with-oas/test-wildcard-operation.png" alt-text="Test wildcard operation"::: |
| 127 | + |
| 128 | +1. Select **Send**. |
| 129 | + |
| 130 | +[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-append-apis.md)] |
| 131 | + |
| 132 | +[!INCLUDE [api-management-define-api-topics.md](../../includes/api-management-define-api-topics.md)] |
| 133 | + |
| 134 | +## Next steps |
| 135 | + |
| 136 | +> [!div class="nextstepaction"] |
| 137 | +> [Transform and protect a published API](transform-api.md) |
0 commit comments