Skip to content

Gravitee.io - API Management - Policy - Request Validation

License

Notifications You must be signed in to change notification settings

gravitee-io/gravitee-policy-request-validation

Repository files navigation

Request validation policy

Gravitee.io License Releases CircleCI

Phase

onRequest onResponse onRequestContent onResponseContent

X

X

Description

You can use the request-validation policy to validate an incoming HTTP request according to defined rules. A rule is defined for an input value. This input value supports Expression Language expressions and is validated against constraint rules.

Constraint rules can be:

  • NOT_NULL — Input value is required

  • MIN — Input value is a number and its value is greater than or equal to a given parameter

  • MAX — Input value is a number and its value is lower than or equal to a given parameter

  • MAIL — Input value is valid according to the mail pattern

  • DATE — Input value is valid according to the date format pattern given as a parameter

  • PATTERN — Input value is valid according to the pattern given as a parameter

  • SIZE — Input value length is between two given parameters

  • ENUM — Field value included in ENUM

By default, if none of the rules can be validated, the policy returns a 400 status code.

Compatibility with APIM

Plugin version

APIM version

1.x

All supported versions

Configuration

Property Required Description Type Default

scope

X

Phase when the policy is executed

Policy scope

ON_REQUEST

status

X

HTTP status code send to the consumer in case of validation issues

HTTP status code

400

rules

X

Rules to apply to incoming request

List of rules

-

Example configuration

"policy-request-validation": {
    "rules": [
        {
            "constraint": {
                "parameters": [
                    ".*\\\\.(txt)$"
                ],
                "type": "PATTERN"
            },
            "input": "{#request.pathInfos[2]}"
        }
    ],
    "status": "400"
}

Errors

HTTP status code

Code Message

400

Incoming HTTP request can not be validated.

Default response override

You can use the response template feature to override the default response provided by the policy. These templates must be defined at the API level (see the API Console Response Templates option in the API Proxy menu).

Error keys

The error keys sent by this policy are as follows:

Key Parameters

REQUEST_VALIDATION_INVALID

violations