将逻辑应用导入为 APIImport a Logic App as an API

本文介绍如何将逻辑应用导入为 API 并测试导入的 API。This article shows how to import a Logic App as an API and test the imported API.

在本文中,学习如何:In this article, you learn how to:

  • 将逻辑应用导入为 APIImport a Logic App as an API
  • 在 Azure 门户中测试 APITest the API in the Azure portal

先决条件Prerequisites

转到你的 API 管理实例Go to your API Management instance

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 选择“所有服务”。Select All services.

  3. 在搜索框中输入 apiIn the search box, enter api.

  4. 在搜索结果中,选择“API 管理服务”。In the search results, select API Management services.

  5. 选择自己的 API 管理服务实例。Select your API Management service instance.

提示

若要将 API 管理添加到 Azure 门户中的收藏夹,请选择星形。To add API Management to your favorites in the Azure portal, select the star.

API 管理图标The API Management icon ((API 管理图标)现在显示在门户的左侧菜单中。) now appears in the left menu in the portal.

导入和发布后端 API Import and publish a back-end API

  1. 在 Azure 门户中导航到 API 管理服务,然后从菜单中选择“API” 。Navigate to your API Management service in the Azure portal and select APIs from the menu.

  2. 从“添加新的 API”列表中选择“逻辑应用” 。Select Logic App from the Add a new API list.

    选择逻辑应用类别

  3. 按“浏览”查看订阅中使用 HTTP 触发器的逻辑应用列表 。Press Browse to see the list of Logic Apps with HTTP trigger in your subscription.

    • 不使用 HTTP 触发器的逻辑应用不会出现在此列表中。Logic apps without HTTP trigger will not appear in the list.

    通过适当的触发器浏览现有逻辑应用

  4. 选择逻辑应用。Select the logic app.

    选择逻辑应用

  5. API 管理找到与所选应用关联的 swagger 后,将其提取并导入。API Management finds the swagger associated with the selected app, fetches it, and imports it.

  6. 添加 API URL 后缀。Add an API URL suffix.

    • 后缀在该 API 管理实例中唯一标识此特定 API。The suffix uniquely identifies this specific API in this API Management instance.

    完成字段

  7. 若要发布 API 并使其可供开发人员使用,请切换到“完整”视图并将其与“产品”关联 。If you want the API to be published and available to developers, Switch to the Full view and associate it with a Product. 本例中使用“无限制”产品。We use the "Unlimited" product in this example.

    • 你可以在创建过程中或之后通过“设置”选项卡将 API 添加到产品中。You can add your API to a product either during creation or later via the Settings tab.

    备注

    产品是通过开发人员门户向开发人员提供的一个或多个 API 的关联。Products are associations of one or more APIs offered to developers through the developer portal. 首先,开发人员必须订阅产品才能访问 API。First, developers must subscribe to a product to get access to the API. 订阅后,他们会得到一个订阅密钥,可用于该产品中的任何 API。Once subscribed, they get a subscription key for any API in that product. 作为 API 管理实例的创建者,你默认成为管理员且订阅了每个产品。As creator of the API Management instance, you are an administrator and are subscribed to every product by default.

    每个 API 管理实例默认附带两个示例产品:Each API Management instance comes with two default sample products:

    • 入门Starter
    • 不受限制Unlimited
  8. 输入其他 API 设置。Enter other API settings.

    • 可以在创建过程中或之后通过转到“设置”选项卡来设置这些值。在导入和发布第一个 API 教程中对这些设置进行了说明。You can set these values during creation or later by going to the Settings tab. The settings are explained in the Import and publish your first API tutorial.
  9. 选择“创建” 。Select Create.

在 Azure 门户中测试 APITest the API in the Azure portal

可直接从 Azure 门户调用操作,这样可以方便地查看和测试 API 的操作。Operations can be called directly from the Azure portal, which provides a convenient way to view and test the operations of an API.

测试逻辑应用

  1. 选择上一步中创建的 API。Select the API you created in the previous step.

  2. 按“测试”选项卡 。Press the Test tab.

  3. 选择要测试的操作。Select the operation you want to test.

    • 该页将显示查询参数和标头的字段。The page displays fields for query parameters and headers.
    • 其中一个标头是“Ocp-Apim-Subscription-Key”,用于提供和此 API 关联的产品订阅密钥。One of the headers is "Ocp-Apim-Subscription-Key", for the product subscription key associated with this API.
    • 作为 API 管理实例的创建者,你已是管理员,因此会自动填充该密钥。As creator of the API Management instance, you are an administrator already, so the key is filled in automatically.
  4. 按“发送”。 Press Send.

    • 如果测试成功,后端以“200 正常”和某些数据做出响应。When the test succeeds, the backend responds with 200 OK and data.

追加其他 APIAppend other APIs

API 可以包含由其他服务公开的 API,这些服务包括 OpenAPI 规范、SOAP API、Azure 应用服务的 API 应用功能、Azure Function App、Azure 逻辑应用和 Azure Service Fabric。An API can be composed of APIs exposed by different services, including the OpenAPI Specification, a SOAP API, the API Apps feature of Azure App Service, Azure Function App, Azure Logic Apps, and Azure Service Fabric.

导入 API

若要将其他 API 追加到现有 API,请完成以下步骤。To append a different API to your existing API, complete the following steps. 导入另一个 API 时,操作将追加到当前 API 后面。When you import another API, the operations are appended to your current API.

  1. 在 Azure 门户中转到自己的 Azure API 管理实例。Go to your Azure API Management instance in the Azure portal.
  2. 在左侧菜单中选择“API”。Select APIs from the menu on the left.
  3. 单击要将另一个 API 追加到的 API 旁边的“...”。Click ... next to the API that you want to append another API to.
  4. 从下拉菜单中选择“导入”。Select Import from the drop-down menu.
  5. 选择要从中导入 API 的服务。Select a service from which to import an API.

备注

每个逻辑应用程序都有一个 manual-invoke 操作。Every Logic App has manual-invoke operation. 若要构造包含多个逻辑应用的 API 并避免冲突,需要将函数重命名。To comprise your API of multiple logic apps and avoid collision, you need to rename the function.

后续步骤Next steps