Amazon API Gateway REST API Reference

requestvalidator:create

Creates a RequestValidator for a specified RestApi.

HTTP Request

POST /restapis/<restapi_id>/requestvalidators

Request Body

{
  "name" : "String",
  "validateRequestBody" : "Boolean",
  "validateRequestParameters" : "Boolean"
}

Request Body Fields

The request accepts the following fields in JSON format.

  • name
  • The name of the to-be-created RequestValidator.

  • validateRequestBody
  • A Boolean flag to indicate whether to validate request body according to the configured model schema for the method (true) or not (false).

  • validateRequestParameters
  • A Boolean flag to indicate whether to validate request parameters, true, or not false.

Response

RequestValidator

Remarks

Example: Create a RequestValidator for an API to validate required request payloads.

Request

The following example request creates a RequestValidator resource for the given RestApi (mkhqppt4e4):

POST /restapis/mkhqppt4e4/requestvalidators HTTP/1.1
Content-Type: application/json
Host: apigateway.us-east-1.amazonaws.com
X-Amz-Date: 20170223T172652Z
Authorization: AWS4-HMAC-SHA256 Credential={access_key_ID}/20170223/us-east-1/apigateway/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature={sig4_hash}

{
  "name" : "body-only",
  "validateRequestBody" : "true",
  "validateRequestParameters" : "false"
}
Response

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

{
  "_links": {
    "self": {
      "href": "/restapis/mkhqppt4e4/requestvalidators/3n5aa0"
    },
    "request-validator-delete": {
      "href": "/restapis/mkhqppt4e4/requestvalidators/3n5aa0"
    },
    "request-validator-update": {
      "href": "/restapis/mkhqppt4e4/requestvalidators/3n5aa0"
    }
  },
  "id": "3n5aa0",
  "name": "body-only",
  "validateRequestBody": true,
  "validateRequestParameters": false
}

When the newly created RequestValidator is associated with a method, Amazon API Gateway will validate the request by verifying the required request payload is valid according to the configured request model for the method before forwarding the request to the back end.

See Also

AWS CLI