Skip to content

Example of request validation in Spring Cloud Gateway

License

Notifications You must be signed in to change notification settings

kkocel/spring-cloud-gateway-request-validation

Repository files navigation

Spring Cloud Gateway Request Validation Example

This repository demonstrates how you can validate request body of incoming requests in Spring Cloud Gateway.

Body inspecting is implemented in BodyGlobalFilter and example validation logic is implemented in SampleBodyValidationFilter.

Any use case that requires request validation can be implemented on gateway level - for example perfect candidates are:

  1. Google backend authentication
  2. SafetyNet Attestation
  3. Alexa request validation

You can read more about this code at Alexa Request Validation with Spring Cloud Gateway .

Building

./gradlew build

Running

./gradlew bootRun

In order to play with requests you can run them from requests folder.

Valid request:

POST http://localhost:8080/example/200
Content-Type: application/json

{"fieldToValidate": "secret"}

Invalid request:

POST http://localhost:8080/example/200
Content-Type: application/json

{"fieldToValidate": "not valid"}