

# 使用 API Gateway REST API 设置网关响应
<a name="set-up-gateway-response-using-the-api"></a>

 在使用 API Gateway REST API 自定义网关响应之前，您必须已创建 API 并获得其标识符。要检索 API 标识符，您可以使用 [restapi:gateway-responses](https://docs.aws.amazon.com/apigateway/latest/api/API_GetGatewayResponses.html) 链接关系并检查结果。

**使用 API Gateway REST API 自定义网关响应**

1. 要覆盖整个 [GatewayResponse](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html) 实例，请调用 [gatewayresponse:put](https://docs.aws.amazon.com/apigateway/latest/api/API_PutGatewayResponse.html) 操作。在 URL 路径参数中指定所需的 [responseType](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html#responseType)，并在请求负载中提供 [statusCode](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html#statusCode)、[responseParameters](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html#responseParameters) 和 [responseTemplates](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html#responseTemplates) 映射。

1. 要更新 `GatewayResponse` 实例的一部分，请调用 [gatewayresponse:update](https://docs.aws.amazon.com/apigateway/latest/api/API_UpdateGatewayResponse.html) 操作。在 URL 路径参数中指定所需的 `responseType`，并在请求中提供所需的单个 `GatewayResponse` 属性，例如，`responseParameters` 或 `responseTemplates` 映射。