教程:导入和发布第一个 APITutorial: Import and publish your first API

本教程介绍如何将 JSON 格式的 OpenAPI 规范后端 API 导入 Azure API 管理。This tutorial shows how to import an OpenAPI Specification backend API in JSON format into Azure API Management. Microsoft 提供本示例中使用的后端 API,并将其托管在 Azure 上 (https://conferenceapi.chinacloudsites.cn?format=json)。Microsoft provides the backend API used in this example, and hosts it on Azure at https://conferenceapi.chinacloudsites.cn?format=json.

将后端 API 导入 API 管理后,API 管理 API 将成为后端 API 的结构。Once you import the backend API into API Management, your API Management API becomes a facade for the backend API. 可以在 API 管理中自定义该结构,而无需修改后端 API。You can customize the facade to your needs in API Management without touching the backend API. 有关详细信息,请参阅转换和保护 APIFor more information, see Transform and protect your API.

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 将 API 导入 API 管理Import an API into API Management
  • 在 Azure 门户中测试 APITest the API in the Azure portal

导入后,可以在 Azure 门户中管理 API。After import, you can manage the API in the Azure portal.

API 管理中新的 API


转到你的 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.

导入和发布后端 APIImport and publish a backend API

本部分介绍如何导入和发布 OpenAPI 规范后端 API。This section shows how to import and publish an OpenAPI Specification backend API.

  1. 在 API 管理实例的左侧导航栏中,选择“API”。In the left navigation of your API Management instance, select APIs.

  2. 选择“OpenAPI”磁贴。Select the OpenAPI tile.

  3. 在“基于 OpenAPI 规范创建”窗口中,选择“完全” 。In the Create from OpenAPI specification window, select Full.

  4. 输入下表中的值。Enter the values from the following table. 然后选择“创建”以创建 API。Then select Create to create your API.

    可以在创建 API 期间设置 API 值,或者以后转到“设置”选项卡进行设置。You can set API values during creation or later by going to the Settings tab.

    创建 API

    设置Setting Value 说明Description
    OpenAPI 规范OpenAPI specification https://conferenceapi.chinacloudsites.cn?format=jsonhttps://conferenceapi.chinacloudsites.cn?format=json 实现 API 的服务。The service implementing the API. API 管理将请求转发到此地址。API Management forwards requests to this address.
    显示名称Display name 输入上述服务 URL 后,API 管理将根据 JSON 填写此字段。After you enter the preceding service URL, API Management fills out this field based on the JSON. 显示在开发人员门户中的名称。The name displayed in the developer portal.
    名称Name 输入上述服务 URL 后,API 管理将根据 JSON 填写此字段。After you enter the preceding service URL, API Management fills out this field based on the JSON. API 的唯一名称。A unique name for the API.
    说明Description 输入上述服务 URL 后,API 管理将根据 JSON 填写此字段。After you enter the preceding service URL, API Management fills out this field based on the JSON. API 的可选说明。An optional description of the API.
    URL 方案URL scheme HTTPSHTTPS 哪些协议可以访问 API。Which protocols can access the API.
    API URL 后缀API URL suffix 会议conference 追加到 API 管理服务基 URL 的后缀。The suffix appended to the base URL for the API Management service. API 管理根据 API 的后缀区分 API,因此后缀对于给定发布者的每个 API 必须唯一。API Management distinguishes APIs by their suffix, so the suffix must be unique for every API for a given publisher.
    标记Tags 用于组织搜索、分组或筛选 API 的标记。Tags for organizing APIs for searching, grouping, or filtering.
    产品Products 不受限制Unlimited 一个或多个 API 的关联。Association of one or more APIs. 每个 API 管理实例附带两个示例产品:初学者无限Each API Management instance comes with two sample products: Starter and Unlimited. 通过将 API 关联到某个产品(在本示例中为“无限制”)来发布该 API。You publish an API by associating the API with a product, Unlimited in this example.

    可在一个产品中包含多个 API,并通过开发人员门户将其提供给开发人员。You can include several APIs in a product and offer them to developers through the developer portal. 若要将此 API 添加到另一个产品,请键入或选择产品名称。To add this API to another product, type or select the product name. 重复此步骤以将 API 添加到多个产品。Repeat this step to add the API to multiple products. 以后也可以从“设置”页将 API 添加到产品。You can also add APIs to products later from the Settings page.

    有关产品的详细信息,请参阅创建和发布产品For more information about products, see Create and publish a product.
    网关Gateways 托管Managed 公开此 API 的 API 网关。API gateway(s) that expose the API. 此字段仅在“开发人员”和“高级”层服务中提供。This field is available only in Developer and Premium tier services.

    “托管”指示内置于 API 管理服务中并由 Microsoft 托管在 Azure 中的网关。Managed indicates the gateway built into the API Management service and hosted by Microsoft in Azure. 自承载网关仅在“高级”和“开发人员”服务层中提供。Self-hosted gateways are available only in the Premium and Developer service tiers. 可以将这些网关部署在本地或其他云中。You can deploy them on-premises or in other clouds.

    如果未选择任何网关,则无法使用此 API,API 请求不会成功。If no gateways are selected, the API won't be available and your API requests won't succeed.
    对此 API 进行版本控制?Version this API? 选择或取消选择Select or deselect 有关详细信息,请参阅发布 API 的多个版本For more information, see Publish multiple versions of your API.


    若要向 API 使用者发布 API,必须将其与某个产品相关联。To publish the API to API consumers, you must associate it with a product.

  5. 选择“创建”。Select Create.

如果在导入 API 定义时遇到问题,请参阅已知问题列表和限制If you have problems importing an API definition, see the list of known issues and restrictions.

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

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

  1. 在 API 管理实例的左侧导航栏中,选择“API” > “演示会议 API” 。In the left navigation of your API Management instance, select APIs > Demo Conference API.

  2. 选择“测试”选项卡,然后选择“GetSpeakers”。 Select the Test tab, and then select GetSpeakers. 页面中会显示“查询参数”和“标头”(如果有)。 The page shows Query parameters and Headers, if any. 对于与此 API 关联的订阅密钥,系统会自动填写“Ocp-Apim-Subscription-Key”。The Ocp-Apim-Subscription-Key is filled in automatically for the subscription key associated with this API.

  3. 选择“发送”。Select Send.

    在 Azure 门户中测试 API

    后端以“200 正常”和某些数据做出响应。The backend responds with 200 OK and some data.

后续步骤Next steps

在本教程中,你了解了如何执行以下操作:In this tutorial, you learned how to:

  • 导入第一个 APIImport your first API
  • 在 Azure 门户中测试 APITest the API in the Azure portal

转到下一教程,了解如何创建和发布产品:Advance to the next tutorial to learn how to create and publish a product: