建立您的 API 中心,以啟動組織的 API 詳細目錄。 Azure API 中心可讓您在集中式位置追蹤 API,以進行探索、重複使用和治理。
建立 API 中心之後,請遵循教學課程中的步驟來新增自訂中繼資料、API、版本、定義和其他資訊。
必要條件
如果您沒有 Azure 訂閱,請在開始之前先建立 Azure 免費帳戶。
Azure 訂用帳戶中至少具有參與者角色指派或對等權限。
對於 Azure CLI:
在 Azure Cloud Shell 中使用 Bash 環境。 如需詳細資訊,請參閱開始使用 Azure Cloud Shell。
若要在本地執行 CLI 參考命令,請安裝 Azure CLI。 若您在 Windows 或 macOS 上執行,請考慮在 Docker 容器中執行 Azure CLI。 如需詳細資訊,請參閱〈如何在 Docker 容器中執行 Azure CLI〉。
如果您使用的是本機安裝,請使用 az login 命令,透過 Azure CLI 來登入。 請遵循您終端機上顯示的步驟,完成驗證程序。 如需其他登入選項,請參閱 使用 Azure CLI 向 Azure 進行驗證。
出現提示時,請在第一次使用時安裝 Azure CLI 延伸模組。 如需擴充功能的詳細資訊,請參閱 使用和管理 Azure CLI 的擴充功能。
執行 az version 以尋找已安裝的版本和相依程式庫。 若要升級至最新版本,請執行 az upgrade。
注意
az apic命令需要apic-extensionAzure CLI 延伸模組。 如果您尚未使用az apic命令,則可以在執行第一個az apic命令時動態安裝延伸模組,也可以手動安裝延伸模組。 深入了解 Azure CLI 延伸模組。
註冊 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 中心定義自訂中繼資料開始。