Request validation for REST APIs in API Gateway (original) (raw)
Overview of basic request validation in API Gateway
You can configure API Gateway to perform basic validation of an API request before proceeding with the integration request. When the validation fails, API Gateway immediately fails the request, returns a 400 error response to the caller, and publishes the validation results in CloudWatch Logs. This reduces unnecessary calls to the backend. More importantly, it lets you focus on the validation efforts specific to your application. You can validate a request body by verifying that required request parameters are valid and non-null or by specifying a model schema for more complicated data validation.
Topics
- Overview of basic request validation in API Gateway
- Data models for REST APIs
- Set up basic request validation in API Gateway
- AWS CloudFormation template of a sample API with basic request validation
Overview of basic request validation in API Gateway
API Gateway can perform the basic request validation, so that you can focus on app-specific validation in the backend. For validation, API Gateway verifies either or both of the following conditions:
- The required request parameters in the URI, query string, and headers of an incoming request are included and not blank.
- The applicable request payload adheres to the configured JSON schema request of the method for a given content type. If no matching content type is found, request validation is not performed. To use the same model regardless of the content type, set the content type for your data model to
$default
.
To turn on validation, you specify validation rules in a request validator, add the validator to the API's map of request validators, and assign the validator to individual API methods.
Enable mock integration using the API Gateway console
Data models for REST APIs
Did this page help you? - Yes
Thanks for letting us know we're doing a good job!
If you've got a moment, please tell us what we did right so we can do more of it.
Did this page help you? - No
Thanks for letting us know this page needs work. We're sorry we let you down.
If you've got a moment, please tell us how we can make the documentation better.