簡體   English   中英

如何使用 Azure 資源管理器在 Azure API 管理中對 API 進行版本控制

[英]How to version an API in Azure API Management using Azure Resource Manager

使用門戶在 Azure API 管理服務中創建新 API 時,可以指定是否希望對 API 進行版本控制。 但是,在使用 ARM 的管理服務中創建 API 時,我找不到復制此方法的方法。 這是目前不支持的,還是我遺漏了什么?

我嘗試在門戶中創建版本化 API,並將創建的模板與非版本化 API 的模板進行比較,但看不出有什么區別。

提前致謝。

要通過 ARM 腳本實現這一點,您需要先創建一個 ApiVersionSet 資源:

{
    "name": "[concat(variables('ManagementServiceName'), '/', variables('VersionSetName'))]",
    "type": "Microsoft.ApiManagement/service/api-version-sets",
    "apiVersion": "2017-03-01",
    "properties": {
        "description": "Api Description",
        "displayName": "Api Name",
        "versioningScheme": "Segment"
    }
}

然后更新Microsoft.ApiManagement/service/apis資源上的apiVersionSetId屬性:

{
        "type": "Microsoft.ApiManagement/service/apis",
        "name": "[concat(variables('ManagementServiceName'), '/', variables('ApiName'))]",
        "apiVersion": "2017-03-01",
        "dependsOn": [
            "[resourceId('Microsoft.ApiManagement/service/api-version-sets', variables('ManagementServiceName'), variables('VersionSetName'))]"
        ],
        "properties": {
            "displayName": "string",
            "apiRevision": "1",
            "description": "",
            "serviceUrl": "string",
            "path": "string",
            "protocols": [
                "https"
            ],
            "isCurrent": true,
            "apiVersion": "v1",
            "apiVersionName": "v1",
            "apiVersionDescription": "string",
            "apiVersionSetId": "[concat('/api-version-sets', variables('VersionSetName'))]"
        }
    }

api-version-sets 的資源

              "name": "my-api-version-sets",
              "type": "api-version-sets",
              "apiVersion": "2018-01-01",
              "properties": {
                "displayName": "Provider API",
                "versioningScheme": "Segment"
              },
              "dependsOn": [
                "[concat('Microsoft.ApiManagement/service/', variables('apiManagementServiceName'))]"
              ]

然后其他到apis

                "apiVersion": "2018-01-01",
                "type": "apis",

                "properties": {
                    ....

                    "isCurrent": true,
                    "apiVersion": "v1",
                    "apiVersionSetId": "/api-version-sets/my-api-version-sets" 

您可以在路徑、標題或查詢字符串中指定 Azure ARM 門戶上的版本。但舊的 azure API 管理門戶不支持構建版本控制。您可以通過任何方式在 Web API URL 后綴中指定版本控制。

如果您有任何問題,請添加一些圖片並描述您的問題。

Azure ARM 門戶(新 APIM)

Azure APIM 門戶(舊)

謝謝,因法茲

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM