如何通过C#创建Azure API管理实例



我一直在使用Microsoft.Azure.Management.Fluent包来创建一个工具,该工具将构建我的环境并进行一些额外的设置。现在,我需要添加一个API管理实例。在Fluent SDK中,我没有看到任何与API管理相关的内容。我假设它没有SDK包装器,我只需要自己进行REST调用。我在找导游。

当前Fluent api不支持API Management。这里有一个问题。

相反,还有另一个包Microsoft.Azure.Management.ApiManagement6.0.0-preview,您可以使用它来创建API Management instance。代码如下:

// you should provide the real credentialhere.
ApiManagementClient client = new ApiManagementClient(the_credential);
//provide the neccesary parameters to create the APIM instance.
client.ApiManagementService.CreateOrUpdate(the_parameters);

创建API Management的另一种方法是使用此api:api管理服务-创建或更新。您可以阅读api文档了解其用法和示例。

您可以使用REST:
Deployments-创建或更新

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2020-06-01

您必须将链接传递到请求正文中的ARM模板:

{
"properties": {
"templateLink": {
"uri": "https://example.com/exampleTemplate.json"
},
"parameters": {},
"mode": "Complete",
"onErrorDeployment": {
"type": "SpecificDeployment",
"deploymentName": "name-of-deployment-to-use"
}
}
}

您可以将ARM模板存储在Blob存储中,并在Body中引用它。

请在GitHub-azure-quickstart-templates 上找到一个示例API-管理ARM模板

最新更新