# ResponseType

Supported types of gateway responses.

Obtainable from: ResponseType.ACCESS_DENIED, ResponseType.API_CONFIGURATION_ERROR, ResponseType.AUTHORIZER_CONFIGURATION_ERROR, ResponseType.AUTHORIZER_FAILURE, ResponseType.BAD_REQUEST_BODY, ResponseType.BAD_REQUEST_PARAMETERS, ResponseType.DEFAULT_4XX, ResponseType.DEFAULT_5XX, ResponseType.EXPIRED_TOKEN, ResponseType.INTEGRATION_FAILURE, ResponseType.INTEGRATION_TIMEOUT, ResponseType.INVALID_API_KEY, ResponseType.INVALID_SIGNATURE, ResponseType.MISSING_AUTHENTICATION_TOKEN, ResponseType.QUOTA_EXCEEDED, ResponseType.REQUEST_TOO_LARGE, ResponseType.RESOURCE_NOT_FOUND, ResponseType.THROTTLED, ResponseType.UNAUTHORIZED, ResponseType.UNSUPPORTED_MEDIA_TYPE, ResponseType.WAF_FILTERED, ResponseType.of

- Source: [`aws-apigateway/lib/gateway-response.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-apigateway/lib/gateway-response.ts#L132)

## Example

TypeScript:

```ts
const api = new apigateway.RestApi(this, 'books-api');
api.addGatewayResponse('test-response', {
  type: apigateway.ResponseType.ACCESS_DENIED,
  statusCode: '500',
  responseHeaders: {
    // Note that values must be enclosed within a pair of single quotes
    'Access-Control-Allow-Origin': "'test.com'",
    'test-key': "'test-value'",
  },
  templates: {
    'application/json': '{ "message": $context.error.messageString, "statusCode": "488", "type": "$context.error.responseType" }'
  }
});
```

Python:

```python
api = apigateway.RestApi(self, "books-api")
api.add_gateway_response("test-response",
    type=apigateway.ResponseType.ACCESS_DENIED,
    status_code="500",
    response_headers={
        # Note that values must be enclosed within a pair of single quotes
        "Access-Control-Allow-Origin": "'test.com'",
        "test-key": "'test-value'"
    },
    templates={
        "application/json": "{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }"
    }
)
```

Java:

```java
RestApi api = new RestApi(this, "books-api");
api.addGatewayResponse("test-response", GatewayResponseOptions.builder()
        .type(ResponseType.ACCESS_DENIED)
        .statusCode("500")
        .responseHeaders(Map.of(
                // Note that values must be enclosed within a pair of single quotes
                "Access-Control-Allow-Origin", "'test.com'",
                "test-key", "'test-value'"))
        .templates(Map.of(
                "application/json", "{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }"))
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
var api = new RestApi(this, "books-api");
api.AddGatewayResponse("test-response", new GatewayResponseOptions {
    Type = ResponseType.ACCESS_DENIED,
    StatusCode = "500",
    ResponseHeaders = new Dictionary<string, string> {
        // Note that values must be enclosed within a pair of single quotes
        { "Access-Control-Allow-Origin", "'test.com'" },
        { "test-key", "'test-value'" }
    },
    Templates = new Dictionary<string, string> {
        { "application/json", "{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }" }
    }
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
api := apigateway.NewRestApi(this, jsii.String("books-api"))
api.AddGatewayResponse(jsii.String("test-response"), &GatewayResponseOptions{
	Type: apigateway.ResponseType_ACCESS_DENIED(),
	StatusCode: jsii.String("500"),
	ResponseHeaders: map[string]*string{
		// Note that values must be enclosed within a pair of single quotes
		"Access-Control-Allow-Origin": jsii.String("'test.com'"),
		"test-key": jsii.String("'test-value'"),
	},
	Templates: map[string]*string{
		"application/json": jsii.String("{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }"),
	},
})
```

## Properties

- `ACCESS_DENIED`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for authorization failure.

- `API_CONFIGURATION_ERROR`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for an invalid API configuration.

- `AUTHORIZER_CONFIGURATION_ERROR`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for failing to connect to a custom or Amazon Cognito authorizer.

- `AUTHORIZER_FAILURE`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when a custom or Amazon Cognito authorizer failed to authenticate the caller.

- `BAD_REQUEST_BODY`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when the request body cannot be validated according to an enabled request validator.

- `BAD_REQUEST_PARAMETERS`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when the request parameter cannot be validated according to an enabled request validator.

- `DEFAULT_4XX`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The default gateway response for an unspecified response type with the status code of 4XX.

- `DEFAULT_5XX`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The default gateway response for an unspecified response type with a status code of 5XX.

- `EXPIRED_TOKEN`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for an AWS authentication token expired error.

- `INTEGRATION_FAILURE`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for an integration failed error.

- `INTEGRATION_TIMEOUT`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for an integration timed out error.

- `INVALID_API_KEY`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for an invalid API key submitted for a method requiring an API key.

- `INVALID_SIGNATURE`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for an invalid AWS signature error.

- `MISSING_AUTHENTICATION_TOKEN`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for a missing authentication token error, including the cases when the client attempts to invoke an unsupported API method or resource.

- `QUOTA_EXCEEDED`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for the usage plan quota exceeded error.

- `REQUEST_TOO_LARGE`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response for the request too large error.

- `RESOURCE_NOT_FOUND`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when API Gateway cannot find the specified resource after an API request passes authentication and authorization.

- `responseType`: string — Valid value of response type.

- `THROTTLED`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when usage plan, method, stage, or account level throttling limits exceeded.

- `UNAUTHORIZED`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when the custom or Amazon Cognito authorizer failed to authenticate the caller.

- `UNSUPPORTED_MEDIA_TYPE`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when a payload is of an unsupported media type, if strict passthrough behavior is enabled.

- `WAF_FILTERED`: [ResponseType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.ResponseType.html) (static) — The gateway response when a request is blocked by AWS WAF.

## Methods

- `of(type: string): ResponseType // chainable` (static) — A custom response type to support future cases.
