导入和发布第一个 APIImport 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 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

新的 API

先决条件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 backend API

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

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

  2. 选择“OpenAPI”磁贴,然后在弹出窗口中选择“完整”。 Select the OpenAPI tile, and then select Full on the pop-up screen.

  3. 在“从 OpenAPI 规范创建”屏幕上,使用下表中的值创建 API。On the Create from OpenAPI specification screen, use the values from the following table to create your API.

    窗体中带有红色星号的字段是必填的。A red star next to a field on the form indicates that the field is required. 可以在创建 API 期间设置 API 值,或者以后转到“设置”选项卡进行设置。You can set API values during creation or later by going to the Settings tab.

    创建 API

    设置Setting ValueValue 说明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 be used to access the API.
    API URL 后缀API URL suffix conferenceconference 追加到 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.
    开发人员必须先订阅产品才能访问 API。To get access to the API, developers must first subscribe to a product. 订阅时,他们会得到一个订阅密钥,此密钥对该产品中的任何 API 都有效。When they subscribe, they get a subscription key that's good for any API in that product.
    如果你创建了 API 管理实例,那么你已是管理员,因此订阅了实例中的每个产品。If you created the API Management instance, you're an administrator already, so you're subscribed to every product in the instance.
    网关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 gateway indicates the gateway built-into the API Management service and hosted by Microsoft in Azure. 其他网关是自承载网关,仅在“高级”和“开发人员”服务层中提供。Other gateways are self-hosted gateways and are available only in the Premium and Developer service tiers. 可以将这些网关部署在本地或其他云中。You can deploy them in 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 about versioning, see Publish multiple versions of your API.

    备注

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

  4. 选择“创建” 。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”,然后选择“演示会议 API”。 In the left navigation of your API Management instance, select APIs from the API Management section, and then select 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.

    测试 API 映射

    后端以“200 正常”和某些数据做出响应。The back end 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: