Amazon API Gateway REST API Reference

gatewayresponse:put

Creates a customization of a GatewayResponse of a specified response type and status code on the given RestApi.

HTTP Request

PUT /restapis/<restapi_id>/gatewayresponses/{response_type}

Template Variable

Request Body

{
  "statusCode" : "String",
  "responseParameters" : {
    "String" : "String"
  },
  "responseTemplates" : {
    "String" : "String"
  }
}

Request Body Fields

The request accepts the following fields in JSON format.

  • statusCode
  • The HTTP status code of the GatewayResponse.
  • responseParameters
  • Response parameters (paths, query strings and headers) of the GatewayResponse as a string-to-string map of key-value pairs.

  • responseTemplates
  • Response templates of the GatewayResponse as a string-to-string map of key-value pairs.

Response

GatewayResponse

Remarks

Example: Set up a Gateway Response of a given response type

Request

PUT /restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN HTTP/1.1
Host: beta-apigateway.us-east-1.amazonaws.com
Content-Type: application/json
X-Amz-Date: 20170503T201609Z
Authorization: AWS4-HMAC-SHA256 Credential={access-key-id}/20170503/us-east-1/apigateway/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=15e138ede132fa8c35c665412f407bd23a9993bdc79b3bef22f1ccccc4c6fac1
Cache-Control: no-cache
Postman-Token: 639177c3-627e-3566-a367-7746659d2360

{
  "statusCode" : "404",
  "responseParameters" : {
      "gatewayresponse.header.x-request-path": "method.request.path.petId",
      "gatewayresponse.header.Access-Control-Allow-Origin": "'a.b.c'",
      "gatewayresponse.header.x-request-query": "method.request.querystring.q",
      "gatewayresponse.header.x-request-header": "method.request.header.Accept"
  },
  "responseTemplates" : {
      "application/json": "{\n     \"message\": $context.error.messageString,\n     \"type\":  \"$context.error.responseType\",\n     \"stage\":  \"$context.stage\",\n     \"resourcePath\":  \"$context.resourcePath\",\n     \"stageVariables.a\":  \"$stageVariables.a\",\n     \"statusCode\": \"'404'\"\n}"
  }
}

Response

The successful operation returns the 201 Created status code and a payload similar to the following:

{
  "_links": {
    "curies": {
      "href": "http://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-gatewayresponse-{rel}.html&quot;,
      "name": "gatewayresponse",
      "templated": true
    },
    "self": {
      "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN"
    },
    "gatewayresponse:delete": {
      "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN"
    },
    "gatewayresponse:put": {
      "href": "/restapis/o81lxisefl/gatewayresponses/{response_type}",
      "templated": true
    },
    "gatewayresponse:update": {
      "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN"
    }
  },
  "defaultResponse": false,
  "responseParameters": {
    "gatewayresponse.header.x-request-path": "method.request.path.petId",
    "gatewayresponse.header.Access-Control-Allow-Origin": "'a.b.c'",
    "gatewayresponse.header.x-request-query": "method.request.querystring.q",
    "gatewayresponse.header.x-request-header": "method.request.header.Accept"
  },
  "responseTemplates": {
    "application/json": "{\n     \"message\": $context.error.messageString,\n     \"type\":  \"$context.error.responseType\",\n     \"stage\":  \"$context.stage\",\n     \"resourcePath\":  \"$context.resourcePath\",\n     \"stageVariables.a\":  \"$stageVariables.a\",\n     \"statusCode\": \"'404'\"\n}"
  },
  "responseType": "MISSING_AUTHENTICATION_TOKEN",
  "statusCode": "404"
}

See Also

Customize Gateway Responses