自訂資源快取參考
本文逐一說明實作快取自訂資源的端點需求。 如果您不熟悉 Azure 自訂資源提供者,請參閱自訂資源提供者概觀。
定義快取資源端點
將 routingType
指定為 "Proxy, Cache" 即可建立 Proxy 資源。
自訂資源提供者範例:
{
"properties": {
"resourceTypes": [
{
"name": "myCustomResources",
"routingType": "Proxy, Cache",
"endpoint": "https://{endpointURL}/"
}
]
},
"location": "eastus",
"type": "Microsoft.CustomProviders/resourceProviders",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}",
"name": "{resourceProviderName}"
}
建立 Proxy 資源端點
實作為 "Proxy, Cache" 資源端點的端點必須處理 Azure 中新 API 的要求和回應。 在此情況下,resourceType 會為 PUT
、GET
、DELETE
和 GET
產生新的 Azure 資源 API,以在單一資源上執行 CRUD,並擷取所有現有的資源:
注意
Azure API 會產生要求方法 PUT
、GET
和 DELETE
,但快取端點只需要處理 PUT
和 DELETE
。
建議這個端點也要實作 GET
。
建立自訂資源
Azure API 傳入要求:
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
{
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
此要求接著會以下列格式轉送至端點:
PUT https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}
{
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
系統會將來自端點的回應轉送回給客戶。 回應應傳回:
- 有效的 JSON 物件文件。 所有陣列和字串都應該在最上層物件下方巢狀化。
Content-Type
標頭應該設定為 "application/json; charset=utf-8"。- 自訂資源提供者會覆寫要求的
name
、type
和id
欄位。 - 自訂資源提供者只會傳回快取端點
properties
物件底下的欄位。
端點回應:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
自訂資源提供者會自動產生自訂資源的 name
、id
和 type
欄位。
Azure 自訂資源提供者回應:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
移除自訂資源
Azure API 傳入要求:
Delete https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
此要求接著會以下列格式轉送至端點:
Delete https://{endpointURL}/?api-version=2018-09-01-preview
Content-Type: application/json
X-MS-CustomProviders-RequestPath: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}
系統會將來自端點的回應轉送回給客戶。 回應應傳回:
- 有效的 JSON 物件文件。 所有陣列和字串都應該在最上層物件下方巢狀化。
Content-Type
標頭應該設定為 "application/json; charset=utf-8"。- 如果傳回 200 層級的回應,Azure 自訂資源提供者只會從其快取中移除該項目。 即使資源不存在,端點也應該會傳回 204。
端點回應:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Azure 自訂資源提供者回應:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
擷取自訂資源
Azure API 傳入要求:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
系統不會將要求轉送至端點。
Azure 自訂資源提供者回應:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
列舉所有自訂資源
Azure API 傳入要求:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources?api-version=2018-09-01-preview
Authorization: Bearer eyJ0e...
Content-Type: application/json
系統不會將要求轉送至端點。
Azure 自訂資源提供者回應:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"value" : [
{
"name": "{myCustomResourceName}",
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomProviders/resourceProviders/{resourceProviderName}/myCustomResources/{myCustomResourceName}",
"type": "Microsoft.CustomProviders/resourceProviders/myCustomResources",
"properties": {
"myProperty1": "myPropertyValue1",
"myProperty2": {
"myProperty3" : "myPropertyValue3"
}
}
}
]
}