共用方式為


快速入門:建立 API 中心 - Azure CLI

建立您的 API 中心,以啟動組織的 API 詳細目錄。 Azure API 中心可讓您在集中式位置追蹤 API,以進行探索、重複使用和治理。

建立 API 中心之後,請遵循教學課程中的步驟來新增自訂中繼資料、API、版本、定義和其他資訊。

必要條件

  • 如果您沒有 Azure 訂閱,請在開始之前先建立 Azure 免費帳戶

  • Azure 訂用帳戶中至少具有參與者角色指派或對等權限。

  • 對於 Azure CLI:

    注意

    az apic 命令需要 apic-extension Azure CLI 延伸模組。 如果您尚未使用 az apic 命令,則可以在執行第一個 az apic 命令時動態安裝延伸模組,也可以手動安裝延伸模組。 深入了解 Azure CLI 延伸模組

    如需 apic-extension 中的最新變更和更新,請參閱版本資訊

註冊 Microsoft.ApiCenter 提供者

如果您尚未在訂用帳戶中註冊 Microsoft.ApiCenter 資源提供者,必須先註冊。 您只需要註冊資源提供者一次。

若要使用 Azure CLI 在您的訂用帳戶中註冊資源提供者,請執行下列 az provider register 命令:

az provider register --namespace Microsoft.ApiCenter

您可以執行下列 az provider show 命令來檢查註冊狀態:

az provider show --namespace Microsoft.ApiCenter

建立資源群組

與所有 Azure 資源一樣,Azure API 中心執行個體必須部署到資源群組中。 資源群組可讓您組織和管理相關的 Azure 資源。

使用 az group create 命令建立資源群組。 下列範例會在美國東部位置建立一個名為 MyGroup 的群組:

az group create --name MyGroup --location eastus

建立 API 中心

使用 az apic create 命令建立 API 中心。

下列範例會在 MyGroup 資源群組中建立一個名為 MyApiCenter 的 API 中心。 在此範例中,API 中心會部署在西歐位置。 取代您選擇的 API 中心名稱 ,然後為您的 API 中心輸入其中一個可用位置

az apic create --name MyApiCenter --resource-group MyGroup --location westeurope

該命令的輸出看起來類似以下內容。 根據預設,API 中心會在免費方案中建立。

{
  "dataApiHostname": "myapicenter.data.westeurope.azure-apicenter.ms",
  "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/mygroup/providers/Microsoft.ApiCenter/services/myapicenter",
  "location": "westeurope",
  "name": "myapicenter",
  "resourceGroup": "mygroup",
  "sku": {
    "name": "Free"
  },
  "systemData": {
    "createdAt": "2024-06-22T21:40:35.2541624Z",
    "lastModifiedAt": "2024-06-22T21:40:35.2541624Z"
  },
  "tags": {},
  "type": "Microsoft.ApiCenter/services"
}

部署之後,您的 API 中心已準備好可供使用!

下一步

現在,您可以開始將資訊新增至 API 中心的詳細目錄。 為了幫助您組織 API 和其他資訊,請從在 API 中心定義自訂中繼資料開始。