将逻辑应用导入为 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
  • 在开发人员门户中测试 APITest the API in the Developer 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 触发器的逻辑应用不会出现在此列表中。)(Note that Logic Apps without HTTP trigger will not appear in the list.)

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

  5. 添加 API URL 后缀。Add an API URL suffix. 后缀是用于在该 API 管理实例中标识此特定 API 的名称。The suffix is a name that identifies this specific API in this API Management instance. 在该 API 管理实例中,后缀必须唯一。It has to be unique in this API Management instance.

  6. 通过关联 API 与产品来发布 API。Publish the API by associating the API with a product. 本例中使用了“无限制”产品 。In this case, the "Unlimited" product is used. 如果想要发布 API 并使其对开发人员可用,请将其添加到产品中。If you want for the API to be published and be available to developers, add it to a product. 可在 API 创建期间执行此操作,或稍后进行设置。You can do it during API creation or set it later.

    产品是一个或多个 API 的关联。Products are associations of one or more APIs. 可以包含多个 API,并通过开发人员门户将其提供给开发人员。You can include a number of APIs and offer them to developers through the developer portal. 开发人员必须先订阅产品才能访问 API。Developers must first subscribe to a product to get access to the API. 订阅时,他们会得到一个订阅密钥,此密钥对该产品中的任何 API 都有效。When they subscribe, they get a subscription key that is good for any API in that product. 如果你创建了 API 管理实例,那么你已是管理员,因此默认情况下订阅了每个产品。If you created the API Management instance, you are an administrator already, so you are subscribed to every product by default.

    默认情况下,每个 API 管理实例附带两个示例产品:By default, each API Management instance comes with two sample products:

    • 入门Starter
    • 不受限制Unlimited
  7. 输入其他 API 设置。Enter other API settings. 可以在创建过程中设置这些值,也可以稍后转到“设置” 选项卡来配置这些值。在导入和发布第一个 API 教程中对这些设置进行了说明。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 tutorial.

  8. 选择“创建” 。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 some operation.

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

  4. 按“发送”。 Press Send.

    后端以“200 正常”和某些数据做出响应 。Backend responds with 200 OK and some 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,为避免冲突,需要将函数重命名。If you want to comprise your API of multiple logic apps, in order not to have collision, you need to rename the function.

后续步骤Next steps