Skip to content

Latest commit

 

History

History
128 lines (74 loc) · 6.15 KB

integrate-with-apim.md

File metadata and controls

128 lines (74 loc) · 6.15 KB

Integrating OpenAPI-enabled Azure Functions with Azure API Management

Azure API Management provides HTTP API consumers with a consistent way of using API gateway features for back-end API services. You can integrate your Azure Function app with Azure API Management by directly importing the Function app. But you can also make use of this OpenAPI extension so that everything will be set up at one go.

Prerequisites

To get yourself started, you need to have the followings installed on your local machine.

Create Azure API Management Instance

There are several ways to create an Azure API Management instance. But Azure CLI will be used here. Run the following command in your shell:

az apim create \
    -g [RESOURCE_GROUP_NAME] \
    -n [API_MANAGEMENT_INSTANCE_NAME] \
    -l [LOCATION] \
    --sku-name Consumption \
    --publisher-name contoso.com \
    --publisher-email apim@contoso.com
    --no-wait

Make sure that, as creating an Azure API Management instance takes about 30-40 minutes, adding the --no-wait parameter would be nice. Also use the SKU of Consumption instead of the default SKU (Developer) to reduce the instance generation time for this practice. The Consumption tier takes up to two minutes for instance creation.

Create Azure Function App

Please refer to the Azure Function app with the OpenAPI extension enabled. Once the Function app is deployed to Azure, make sure you can generate swagger.json document on-the-fly.

swagger.json on Azure

Copy the URL of the swagger.json for later use.

The sample Function app code can be found at this GitHub repository.

Import Azure Function App into Azure API Management

On you Azure API Management instance, select APIs blade, select + Add API tab and click the OpenAPI panel.

APIM APIs blade

Paste the URL copied from the previous step into the OpenAPI specification field and enter contoso into the API URL suffix field. All the rest are automatically filled in.

Import swagger.json

Azure Functions API is now successfully imported.

swagger.json successfully imported

Test API Endpoint through Azure API Management

To test the imported API endpoint, go to the newly imported API by clicking the APIs blade, clicking the OpenAPI Sample on Azure... tab and choosing one of API endpoints, and selecting the Test tab.

Testing imported API endpoint

Enter relevant information to the given fields anc click the Send button

Enter necessary information for HTTP API endpoint testing

Confirm the test has been successfully performed.

Test successful

Clean-up Resources

When you continue to the another step, [Support Azure Functions v1 with OpenAPI Extension][docs v1 suppport], you'll need to keep all your resources in place to build on what you've already done.

Otherwise, you can use the following steps to delete the function app and its related resources to avoid incurring any further costs.

  1. In Visual Studio Code, press F1 to open the command palette. In the command palette, search for and select Azure Functions: Open in portal.

  2. Choose your function app, and press Enter. The function app page opens in the Azure portal.

  3. In the Overview tab, select the named link next to Resource group.

    Select the resource group to delete from the function app page

  4. In the Resource group page, review the list of included resources, and verify that they are the ones you want to delete.

  5. Select Delete resource group, and follow the instructions.

    Deletion may take a couple of minutes. When it's done, a notification appears for a few seconds. You can also select the bell icon at the top of the page to view the notification.

To learn more about Functions costs, see Estimating Consumption plan costs. To learn more about API Management costs, see Feature-based comparison of the Azure API Management tiers.

Next Steps

You have got an Azure API Management integrated with Azure Functions that implements the OpenAPI extension. In the next articles, you will be able to support Azure Functions v1 runtime or integrate this OpenAPI-enabled Azure Functions app with either Azure Logic Apps or Power Platform.