Amazon API Gateway REST API Reference

gatewayresponse:update

Updates a GatewayResponse of a specified response type on the given RestApi.

HTTP Request

PATCH /restapis/<restapi_id>/gatewayresponses/<response_type>

Request Body

{
  "patchOperations" : [ {
    "op" : "String",
    "path" : "String",
    "value" : "String",
    "from" : "String"
  } ]
}

Request Body Fields

The request accepts the following fields in JSON format.

  • patchOperations
  • A list of update operations to be applied to the specified resource and in the order specified in this list.

    • op
    • An update operation to be performed with this PATCH request. The valid value can be "add", "remove", or "replace". Not all valid operations are supported for a given resource. Support of the operations depends on specific operational contexts. Attempts to apply an unsupported operation on a resource will return an error message.

    • path
    • The op operation's target, as identified by a JSON Pointer value that references a location within the targeted resource. For example, if the target resource has an updateable property of {"name":"value"}, the path for this property is /name. If the name property value is a JSON object (e.g., {"name": {"child/name": "child-value"}}), the path for the child/name property will be /name/child~1name. Any slash ("/") character appearing in path names must be escaped with "~1", as shown in the example above. Each op operation can have only one path associated with it.

    • value
    • The new target value of the update operation. When using AWS CLI to update a property of a JSON value, enclose the JSON object with a pair of single quotes in a Linux shell, e.g., '{"a": ...}'. In a Windows shell, see Using JSON for Parameters.

    • from
    • Not supported.

Response

GatewayResponse

Remarks

For more information about valid gateway response types, see Gateway Response Types Supported by Amazon API Gateway

The following table shows the supported and unsupported op operations for updateable GatewayResponse properties of the specified path values.


Updateable property path op = add op = replace op = remove
/statusCode Not supported Supported Not supported
/responseParameters Supported Supported Supported
/responseTemplates Supported Supported Supported

Example: Update a gateway response

Request

The following example updates a MISSING_AUTHENTICATION_TOKEN gateway response by modifying its statusCode, changing the CORS support to the example.com domain, and adding a new body mapping template for an output of the application/xml content type.

PATCH /restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN HTTP/1.1
Host: apigateway.us-east-1.amazonaws.com
Content-Type: application/json
X-Amz-Date: 20170503T070722Z
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=69cc3552631a97....875d6931c497ace2
Cache-Control: no-cache
Postman-Token: 4ffd6473-f1e9-3b91-735d-658306e319de

{
  "patchOperations" : [ 
  {
    "op" : "replace",
    "path" : "/statusCode",
    "value" : "444" 
  }, {
    "op" : "replace",
    "path" : "/responseParameters/gatewayresponse.header.Access-Control-Allow-Origin",
    "value" : "'example.com'"
  }, {
    "op" : "add",
    "path" : "/responseTemplates/application~1xml",
    "value" : "<gatewayResponse><message>$context.error.messageString</message><type>$context.error.responseType</type></gatewayResponse>"
  } ]
}

Notice that application/json is escaped to application~1json as the path value.

Response

The PATCH request returns a 200 OK response with the following body:


  "_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": "'example.com'",
    "gatewayresponse.header.x-request-query": "method.request.querystring.q",
    "gatewayresponse.header.x-request-header": "method.request.header.Accept"
  },
  "responseTemplates": {
    "application/xml": "<gatewayResponse><message>$context.error.messageString</message><type>$context.error.responseType</type></gatewayResponse>",
    "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": "444"
}

See Also

Customize Gateway Responses