x-amazon-apigateway-gateway-回應。 responseTemplates 物件 - Amazon API 网关

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

x-amazon-apigateway-gateway-回應。 responseTemplates 物件

將對應範本定義為指定閘道回 string-to-string 應的索引鍵值配對對GatewayResponse映。每個鍵值對的鍵都是內容類型。例如 "application/json",而值則是簡單變數替換的字串化對應範本。速度範本語言 (VTL) 引擎不會處理GatewayResponse對應範本

屬性名稱 類型 描述
content-type string

僅支援簡單變數替換的 GatewayResponse 內文對應範本,用以自訂閘道回應內文。

x-amazon-apigateway-gateway-回應。 responseTemplates 例子

以下 Open API 擴充功能範例顯示了一個GatewayResponse對應範本,可將API閘道產生的錯誤回應自訂為應用程式特定格式。

"responseTemplates": { "application/json": "{ \"message\": $context.error.messageString, \"type\":$context.error.responseType, \"statusCode\": '488' }" }

下列 Open API 擴充功能範例顯示一個GatewayResponse對應範本,用來覆寫API閘道產生的錯誤回應,並顯示靜態錯誤訊息。

"responseTemplates": { "application/json": "{ \"message\": 'API-specific errors' }" }