Skip to content

Personalized API Gateway with Customized Predicates and Filters (By: Spring Cloud Gateway)

Notifications You must be signed in to change notification settings

pmvieira93/personalized-api-gateway

Repository files navigation

Spring Cloud Gateway

Initializer

Docker Commands

Run Service

docker-compose up --build -d

Stop Service

docker-compose down

Setup FGA & Environment

Initializer FGA Service

newman run fga-initializer.postman_collection.json --export-globals ./target/generated-ids.json

Parse IDs into .env file

jq -r '.values | map("export \(.key|sub("-";"_"; "g")|ascii_upcase)=\(.value|tostring)")|.[]' ./target/generated-ids.json > ./target/.spring-env

Load Env variables

source .spring-env

Maven Commands

Run application

mvnw spring-boot:run

Debug mode

mvnw spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Compile Application

mvnw clean compile

Test Commands

Unit & Integration Tests

mvnw verify

Running all tests

mvnw test

Running specific test class

mvnw -Dtest=RouteGatewayFilterIntegrationTest test

Manually Tests

Testing Routes using default Predicates/Filters

# Test Route: 'code_rewrite_route'
curl -v 'http://localhost:8080/foo/ip' -H 'host: pedro.rewrite.org'

# Test Route: 'yml_header_path_rewrite_route'
curl -v 'http://localhost:8080/self/ip' -H 'X-Request-Id: 123'

Personalized Filters and Predicates

Manually Tests

Testing Routes using personalized Predicates/Filters

ApiVersionValidation

# Test Route: 'code_path_rewrite_apiversion_route'
#   > Expected: 200
curl -v 'http://localhost:8080/version/ip' -H 'api-version: 4.5.0'
#   > Expected: 403
curl -v 'http://localhost:8080/version/ip' -H 'api-version: 1.5.0'
# Test Route: 'httpbin_apiversionfilter_v1_route' (Default Header)
#   > Expected: 200
curl -v 'http://localhost:8080/v1/ip' -H 'api-version: 4.5.0'
#   > Expected: 403
curl -v 'http://localhost:8080/v1/ip' -H 'api-version: 1.5.0'

# Test Route: 'httpbin_apiversionfilter_v1_route' (Configured Header)
#   > Expected: 200
curl -v 'http://localhost:8080/v1/ip' -H 'ApiVersion: 4.5.0'
#   > Expected: 403
curl -v 'http://localhost:8080/v1/ip' -H 'ApiVersion: 1.5.0'

TraceRequest

# Test Route: 'httpbin_trace_route'
#   > Expected: 200
curl -v 'http://localhost:8080/trace/ip' -H 'dummy: trace'

References

About

Personalized API Gateway with Customized Predicates and Filters (By: Spring Cloud Gateway)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages