匯入和發佈您的第一個 APIImport and publish your first API

本教學課程示範如何匯入位於 https://conferenceapi.azurewebsites.net?format=json 的「OpenAPI 規格」後端 API。This tutorial shows how to import an "OpenAPI specification" backend API residing at https://conferenceapi.azurewebsites.net?format=json. 這個後端 API 是由 Microsoft 所提供且裝載於 Azure 上。This backend API is provided by Microsoft and hosted on Azure.

一旦將此後端 API 匯入至 API 管理 (APIM),APIM API 就會變成適用於此後端 API 的外觀。Once the backend API is imported into API Management (APIM), the APIM API becomes a facade for the backend API. 當您匯入此後端 API 時,來源 API 和 APIM API 會完全相同。At the time you import the backend API, both the source API and the APIM API are identical. APIM 可讓您根據需求自訂外觀,而不需碰觸到後端 API。APIM enables you to customize the facade according to your needs without touching the backend API. 如需詳細資訊,請參閱轉換及保護您的 APIFor more information, see Transform and protect your API.

在本教學課程中,您了解如何:In this tutorial, you learn how to:

  • 匯入第一個 APIImport your first API
  • 在 Azure 入口網站中測試 APITest the API in the Azure portal
  • 在開發人員入口網站中測試 APITest the API in the Developer portal

新增 API

必要條件Prerequisites

移至您的 API 管理執行個體Go to your API Management instance

瀏覽至 API 管理執行個體

  1. 登入 Azure 入口網站Sign in to the Azure portal.

  2. 選取 [所有服務] 。Select All services.

  3. 在搜尋方塊中,輸入 api managementIn the search box, enter api management.

  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] 。Select APIs from under API MANAGEMENT.

  2. 從清單中選取 [OpenAPI 規格] ,然後在快顯視窗中按一下 [完整] 。Select OpenAPI specification from the list and click Full in the pop-up.

    建立 API

    您可以在建立期間或稍後前往 [設定] 索引標籤來設定 API 值。欄位旁的紅色星號表示此為必要欄位。You can set the API values during creation or later by going to the Settings tab. The red star next to a field indicates that the field is required.

    請使用下表中的值建立您的第一個 API。Use the values from the table below to create your first API.

    設定Setting Value 說明Description
    OpenAPI 規格OpenAPI Specification https://conferenceapi.azurewebsites.net?format=json 參考實作 API 的服務。References the service implementing the API. API 管理則將要求轉送至此位址。API management forwards requests to this address.
    顯示名稱Display name Demo Conference APIDemo Conference API 如果您在輸入服務 URL 之後按下 Tab,APIM 將根據 json 中的內容填寫此欄位。If you press tab after entering the service URL, APIM will fill out this field based on what is in the json.
    此名稱會顯示於開發人員入口網站中。This name is displayed in the Developer portal.
    名稱Name demo-conference-apidemo-conference-api 為 API 提供唯一的名稱。Provides a unique name for the API.
    如果您在輸入服務 URL 之後按下 Tab,APIM 將根據 json 中的內容填寫此欄位。If you press tab after entering the service URL, APIM will fill out this field based on what is in the json.
    說明Description 提供 API 的選擇性描述。Provide an optional description of the API. 如果您在輸入服務 URL 之後按下 Tab,APIM 將根據 json 中的內容填寫此欄位。If you press tab after entering the service URL, APIM will fill out this field based on what is in the json.
    URL 配置URL scheme HTTPSHTTPS 決定可使用哪些通訊協定來存取 API。Determines which protocols can be used to access the API.
    API URL 尾碼API URL suffix conferenceconference 這個尾碼會附加到 API 管理服務的基底 URL。The suffix is appended to the base URL for the API management service. API 管理依尾碼來區分 API,因此,特定發行者的每一個 API 必須有唯一的尾碼。API Management distinguishes APIs by their suffix and therefore the suffix must be unique for every API for a given publisher.
    產品Products 無限制Unlimited 產品是一或多個 API 的關聯。Products are associations of one or more APIs. 您可以將數個 API 納入產品中,並透過開發人員入口網站將它們提供給開發人員。You can include a number of APIs into a Product and offer them to developers through the developer portal.
    透過將 API 關聯至某個產品來發佈 API (在此範例中為 [無限制] )。You publish the API by associating the API with a product (in this example, Unlimited). 若要將這個新的 API 新增至產品,請輸入產品名稱 (您也可以稍後從 [設定] 頁面進行此作業)。To add this new API to a product, type the product name (you can also do it later from the Settings page). 可以重複此步驟多次來將 API 加入多個產品。This step can be repeated multiple times to add the API to multiple products.
    為了取得 API 的存取權,開發人員必須先訂閱產品。To get access to the API, developers must first subscribe to a product. 當他們訂閱時,就能取得適用於該產品中任何 API 的中訂用帳戶金鑰。When they subscribe, they get a subscription key that is good for any API in that product.
    如果您建立了 APIM 執行個體,表示您已經是系統管理員,因此已訂閱每一個產品。If you created the APIM instance, you are an administrator already, so you are subscribed to every product.
    依預設,每個 API 管理執行個體會隨附兩個範例產品:[入門] 和 [無限制] 。By default, each API Management instance comes with two sample products: Starter and Unlimited.
    標記Tags 用來組織 API 的標記。Tags for organizing APIs. 標記可用於搜尋、分組或篩選。Tags can be used for searching, grouping, or filtering.
    要為此 API 設定版本嗎?Version this API? 如需版本設定的詳細資訊,請參閱發佈多個 API 版本For more information about versioning, see Publish multiple versions of your API

    注意

    若要發佈 API,您必須將它與產品產生關連。To publish the API, you must associate it with a product. 您可以從 [設定] 頁面執行此作業。You can do it from the Settings page.

  3. 選取 [建立] 。Select Create.

提示

如果您在匯入自己的 API 定義時發生問題,請查看已知問題和限制的清單If you are experiencing problems with import of your own API definition, see the list of known issues and restrictions.

在 Azure 入口網站中測試新的 APIM APITest the new APIM API in the Azure portal

測試 API 對應

您可以從 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 (從 [API] 索引標籤)。Select the API you created in the previous step (from the APIs tab).

  2. 按 [測試] 索引標籤。Press the Test tab.

  3. 按一下 [GetSpeakers] 。Click on GetSpeakers. 此頁面會顯示查詢參數的欄位 (在此案例中沒有此欄位) 和標頭。The page displays fields for query parameters, in this case none, and 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. 系統會自動填入金鑰。The key is filled in automatically.

  4. 按 [傳送] 。Press Send.

    後端會回應 200 確定與部分資料。Backend responds with 200 OK and some data.

從開發人員入口網站呼叫作業 Call an operation from the developer portal

您也可以從開發人員入口網站呼叫作業來測試 API。Operations can also be called from the Developer portal to test APIs.

  1. 瀏覽至開發人員入口網站Navigate to the Developer portal.

    開發人員入口網站

  2. 選取 [APIS] ,按一下 [Demo Conference API] ,然後按一下 [GetSpeakers] 。Select APIS, click on Demo Conference API and then GetSpeakers.

    此頁面會顯示查詢參數的欄位 (在此案例中沒有此欄位) 和標頭。The page displays fields for query parameters, in this case none, and 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. 如果您建立了 APIM 執行個體,您就已經是系統管理員,因此會自動填入此金鑰。If you created the APIM instance, you are an administrator already, so the key is filled in automatically.

  3. 按 [試試看] 。Press Try it.

  4. 按 [傳送] 。Press Send.

    叫用作業之後,開發人員入口網站就會顯示回應。After an operation is invoked, the developer portal shows the responses.

後續步驟 Next steps

在本教學課程中,您已了解如何:In this tutorial, you learned how to:

  • 匯入第一個 APIImport your first API
  • 在 Azure 入口網站中測試 APITest the API in the Azure portal
  • 在開發人員入口網站中測試 APITest the API in the Developer portal

前進到下一個教學課程:Advance to the next tutorial: