### Example Response for All Routes (Verbose) Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc This JSON array shows an example response for retrieving all routes in the verbose format. It includes details like predicate, route_id, filters, uri, and order for each route. ```json [ { "predicate": "Paths: [/first], match trailing slash: true", "route_id": "first_route", "filters": [ "[[PreserveHostHeader], order = 0]" ], "uri": "https://www.uri-destination.org", "order": 0 }, { "predicate": "Paths: [/second], match trailing slash: true", "route_id": "second_route", "filters": [], "uri": "https://www.uri-destination.org", "order": 0 } ] ``` -------------------------------- ### Configure RequestRateLimiter via Properties Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestratelimiter-factory.adoc Example of a shortcut configuration for the RequestRateLimiter filter. ```properties spring.cloud.gateway.routes[0].filters[0]=RequestRateLimiter=2, 2, #{@userkeyresolver} ``` -------------------------------- ### Example Forwarded Header Output Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/httpheadersfilters.adoc Shows the format of the Forwarded header when the 'by' parameter is enabled. ```text Forwarded: for="192.0.2.60:47011";proto=https;host="example.com:443";by="198.51.100.17:8080" ``` -------------------------------- ### Define a Simple GET Route Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/java-routes-api.adoc Creates a basic GET route that forwards requests to a specified URI. Ensure necessary imports are included. ```java import static org.springframework.web.servlet.function.RouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; class SimpleGateway { @Bean public RouterFunction getRoute() { return route().GET("/get", http()) .before(uri("https://example.org")) .build(); } } ``` -------------------------------- ### Configure SetPath Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/setpath.adoc Examples showing how to define the SetPath filter using YAML configuration or the Java DSL. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: setpath_route uri: https://example.org predicates: - Path=/red/{segment} filters: - SetPath=/{segment} ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.setPath; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsSetPath() { return route("setpath_route") .GET("/red/{segment}", http()) .before(uri("https://example.org")) .before(setPath("/{segment")) .build(); } } ``` -------------------------------- ### Configure StripContextPath Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/stripcontextpath.adoc Examples showing how to configure the StripContextPath filter using YAML and Java DSL. ```yaml server: servlet: context-path: /context spring: cloud: gateway: server: webmvc: routes: - id: strip_context_path_route uri: https://example.org predicates: - Path=/name/** filters: - StripContextPath - StripPrefix=1 ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.stripContextPath; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.stripPrefix; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsStripContextPath() { return route("strip_context_path_route") .GET("/name/**", http()) .before(uri("https://example.org")) .before(stripContextPath()) .before(stripPrefix(1)) .build(); } } ``` -------------------------------- ### Get All Routes Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Displays the list of all routes defined in the gateway by making a GET request to `/actuator/gateway/routes`. ```APIDOC ## GET /actuator/gateway/routes ### Description Retrieves a list of all routes currently defined in the Spring Cloud Gateway. ### Method GET ### Endpoint /actuator/gateway/routes ### Response #### Success Response (200 OK) Returns a JSON array of route objects. Each object contains details like `predicate`, `filters`, `uri`, and `order`. ``` -------------------------------- ### Configure FallbackHeaders in YAML Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/fallback-headers.adoc Example configuration for the FallbackHeaders filter within an application.yml file. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: ingredients uri: lb://ingredients predicates: - Path=/ingredients/** filters: - name: CircuitBreaker args: name: fetchIngredients fallbackUri: forward:/fallback - id: ingredients-fallback uri: http://localhost:9994 predicates: - Path=/fallback filters: - name: FallbackHeaders args: executionExceptionTypeHeaderName: Test-Header ``` -------------------------------- ### Configure SetRequestHostHeader Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/setrequesthostheader.adoc Examples showing how to configure the SetRequestHostHeader filter using YAML configuration or Java DSL. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: set_request_host_header_route uri: http://localhost:8080 predicates: - Path=/headers filters: - name: SetRequestHostHeader args: host: example.org ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.setRequestHostHeader; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsSetRequestHostHeader() { return route("set_request_host_header_route") .GET("/headers", http()) .before(uri("http://localhost:8080")) .before(setRequestHostHeader("example.org")) .build(); } } ``` -------------------------------- ### Configure KeyResolver bean Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestratelimiter-factory.adoc Example of defining a KeyResolver bean in Java that extracts a user parameter from query strings. ```java @Bean KeyResolver userKeyResolver() { return exchange -> Mono.just(exchange.getRequest().getQueryParams().getFirst("user")); } ``` -------------------------------- ### Configure FallbackHeaders in Java Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/fallback-headers.adoc Example usage of the FallbackHeaders filter using the Java DSL for route configuration. ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.fallbackHeaders; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.filter.CircuitBreakerFilterFunctions.circuitBreaker; import static org.springframework.cloud.gateway.server.mvc.filter.LoadBalancerFilterFunctions.lb; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsCircuitBreakerFallbackToGatewayRoute() { return route("ingredients") .route(path("/ingredients/**"), http()) .filter(lb("ingredients")) .filter(circuitBreaker("fetchIngredients", URI.create("forward:/fallback"))) .build() .and(route("ingredients-fallback") .route(path("/fallback"), http()) .before(uri("http://localhost:9994")) .before(fallbackHeaders()) .build()); } } ``` -------------------------------- ### Configure Basic CircuitBreaker Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/circuitbreaker-filter-factory.adoc This example shows how to apply a basic circuit breaker to a route using the `CircuitBreaker` filter in `application.yml`. Ensure `spring-cloud-starter-circuitbreaker-reactor-resilience4j` is on the classpath. ```yaml spring: cloud: gateway: server: webflux: routes: - id: circuitbreaker_route uri: https://example.org filters: - CircuitBreaker=myCircuitBreaker ``` -------------------------------- ### Configure CircuitBreaker with Fallback URI Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/circuitbreaker-filter-factory.adoc This example demonstrates configuring a circuit breaker with a `fallbackUri` in `application.yml`. The request will be forwarded to the specified `fallbackUri` if the circuit breaker trips. Only `forward:` schemed URIs are currently supported. ```yaml spring: cloud: gateway: server: webflux: routes: - id: circuitbreaker_route uri: lb://backing-service:8088 predicates: - Path=/consumingServiceEndpoint filters: - name: CircuitBreaker args: name: myCircuitBreaker fallbackUri: forward:/inCaseOfFailureUseThis - RewritePath=/consumingServiceEndpoint, /backingServiceEndpoint ``` -------------------------------- ### Configure RewriteLocationResponseHeader GatewayFilter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/rewritelocationresponseheader-factory.adoc Configuration example for the RewriteLocationResponseHeader filter in an application.yml file. ```yaml spring: cloud: gateway: server: webflux: routes: - id: rewritelocationresponseheader_route uri: http://example.org filters: - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, , ``` -------------------------------- ### Configure Method and Path Route Predicate in Java Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/gateway-request-predicates.adoc Configure a route that matches both a specific HTTP method (GET) and a path (/mypath) using Java. ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsMethodAndPath() { return route("method_and_path_route") .GET("/mypath", http()) .before(uri("https://example.org")) .build(); } } ``` -------------------------------- ### Configure RewritePath Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/rewritepath.adoc Examples showing how to define a RewritePath filter using YAML configuration and Java RouterFunctions. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: rewritepath_route uri: https://example.org predicates: - Path=/red/** filters: - RewritePath=/red/?(?.*), /${segment} ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.rewritePath; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsRewritePath() { return route("rewritepath_route") .GET("/red/**", http()) .before(uri("https://example.org")) .before(rewritePath("/red/(?.*)", "/${segment}")) .build(); } } ``` -------------------------------- ### Configure Weight-Based Routing with Java Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/gateway-request-predicates.adoc Implements weighted routing using Java configuration. This setup directs approximately 80% of traffic to 'weighthigh.org' and 20% to 'weightlow.org' based on the 'group1' weight. ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.path; import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.weight; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsWeights() { return route("weight_high") .route(weight("group1", 8).and(path("/**")), http()) .before(uri("https://weighthigh.org")) .build().and( route("weight_low") .route(weight("group1", 2).and(path("/**")), http()) .before(uri("https://weightlow.org")) .build()); } } ``` -------------------------------- ### Configure Baseline Version Route Predicate Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc This example configures a route that matches requests with an API version of '1.1' or any later version, using a baseline version strategy. ```yaml spring: cloud: gateway: server: webflux: routes: - id: version_11_plus_route uri: https://example.org predicates: - Path=/api/** - Version=1.1+ ``` -------------------------------- ### Define Gateway Routes with Fluent Java API Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/fluent-java-routes-api.adoc Use `RouteLocatorBuilder` to define routes programmatically. This example shows how to configure routes with host and path predicates, add response headers using filters, and specify target URIs. It also demonstrates applying a throttle filter. ```java // static imports from GatewayFilters and RoutePredicates @Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder, ThrottleGatewayFilterFactory throttle) { return builder.routes() .route(r -> r.host("**.abc.org").and().path("/image/png") .filters(f -> f.addResponseHeader("X-TestHeader", "foobar")) .uri("http://httpbin.org:80") ) .route(r -> r.path("/image/webp") .filters(f -> f.addResponseHeader("X-AnotherHeader", "baz")) .uri("http://httpbin.org:80") .metadata("key", "value") ) .route(r -> r.order(-1) .host("**.throttle.org").and().path("/get") .filters(f -> f.filter(throttle.apply(1, 1, 10, TimeUnit.SECONDS))) .uri("http://httpbin.org:80") .metadata("key", "value") ) .build(); } ``` -------------------------------- ### Verbose Actuator Route Format Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Example of the verbose format for the /actuator/gateway/routes endpoint, showing detailed route information. ```json [ { "predicate": "(Hosts: [**.addrequestheader.org] && Paths: [/headers], match trailing slash: true)", "route_id": "add_request_header_test", "filters": [ "[[AddResponseHeader X-Response-Default-Foo = 'Default-Bar'], order = 1]", "[[AddRequestHeader X-Request-Foo = 'Bar'], order = 1]", "[[PrefixPath prefix = '/httpbin'], order = 2]" ], "uri": "lb://testservice", "order": 0 } ] ``` -------------------------------- ### Configure LocalResponseCache Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/local-cache-response-filter.adoc Examples of enabling the LocalResponseCache filter using both Java configuration and YAML properties. ```java @Bean public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() .route("rewrite_response_upper", r -> r.host("*.rewriteresponseupper.org") .filters(f -> f.prefixPath("/httpbin") .localResponseCache(Duration.ofMinutes(30), "500MB") ).uri(uri)) .build(); } ``` ```yaml spring: cloud: gateway: routes: - id: resource uri: http://localhost:9000 predicates: - Path=/resource filters: - LocalResponseCache=30m,500MB ``` -------------------------------- ### Weight Route Predicate Factory Example Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc Configures weighted routing for a group of routes, distributing traffic proportionally based on assigned weights. ```yaml spring: cloud: gateway: server: webflux: routes: - id: weight_high uri: https://weighthigh.org predicates: - Weight=group1, 8 - id: weight_low uri: https://weightlow.org predicates: - Weight=group1, 2 ``` -------------------------------- ### Build and Test Spring Cloud Gateway Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/README.adoc Build the source code and run tests for Spring Cloud Gateway. Ensure Java 17 is installed. Maven 3.3.3 or higher is recommended. ```bash ./mvnw install ``` -------------------------------- ### Configure CircuitBreaker with URI Variables Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/circuitbreaker-filter.adoc Example demonstrating the use of URI variables in a fallback URI to support dynamic routing based on path patterns. ```java import java.net.URI; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.filter.CircuitBreakerFilterFunctions.circuitBreaker; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsCircuitBreakerFallback() { return route("circuitbreaker_route") ``` -------------------------------- ### Remote Address Route Predicate Factory Example Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc Configures a route to match requests originating from a specified IP address or subnet. ```yaml spring: cloud: gateway: server: webflux: routes: - id: remoteaddr_route uri: https://example.org predicates: - RemoteAddr=192.168.1.1/24 ``` -------------------------------- ### Route Configuration with AdaptCachedBody Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/adaptcachedbody.adoc This example demonstrates how to configure a route using the Java DSL to cache and adapt the request body. It reads the raw request body as a String, performs potential validation or logging, and then ensures the body is forwarded to the downstream service using `adaptCachedBody()`. ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.adaptCachedBody; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsCachedBody() { return route("cached_body_route") .route(path("/api/**"), http()) .before(uri("https://example.org")) .before(request -> { // Read the body and store it in the request attributes. // Subsequent calls to request.body() or servletRequest().getInputStream() // will see the cached bytes. Optional body = MvcUtils.cacheAndReadBody(request, String.class); // <1> body.ifPresent(b -> { // e.g. validate an HMAC, log, or transform }); return request; }) .before(adaptCachedBody()) // <2> .build(); } } ``` -------------------------------- ### Retrieve All Routes Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Make a GET request to /actuator/gateway/routes to retrieve all routes defined in the gateway. The default response is in a verbose format. ```http GET /actuator/gateway/routes ``` -------------------------------- ### Query Route Predicate Factory Example Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc Matches requests containing a specific query parameter with a value matching a given regular expression. ```yaml spring: cloud: gateway: server: webflux: routes: - id: query_route uri: https://example.org predicates: - Query=red, gree. ``` -------------------------------- ### Configure CircuitBreaker with Fallback URI in Java Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/circuitbreaker-filter-factory.adoc This Java configuration achieves the same result as the YAML example, setting up a circuit breaker with a fallback URI. It also shows optional Spring Cloud LoadBalancer integration. ```java @Bean public RouteLocator routes(RouteLocatorBuilder builder) { return builder.routes() .route("circuitbreaker_route", r -> r.path("/consumingServiceEndpoint") .filters(f -> f.circuitBreaker(c -> c.name("myCircuitBreaker").fallbackUri("forward:/inCaseOfFailureUseThis")) .rewritePath("/consumingServiceEndpoint", "/backingServiceEndpoint")).uri("lb://backing-service:8088")) .build(); } ``` -------------------------------- ### Configure SetPath GatewayFilter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/setpath-factory.adoc This example configures a SetPath GatewayFilter in application.yml. It sets the request path to a templated segment. For a request path of /red/blue, this sets the path to /blue before the downstream request. ```yaml spring: cloud: gateway: server: webflux: routes: - id: setpath_route uri: https://example.org predicates: - Path=/red/{segment} filters: - SetPath=/{segment} ``` -------------------------------- ### Configure MapRequestHeader Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/maprequestheader-factory.adoc This example configures the `MapRequestHeader` filter in `application.yml`. It maps the `Blue` header from the incoming request to the `X-Request-Red` header in the downstream request. ```yaml spring: cloud: gateway: server: webflux: routes: - id: map_request_header_route uri: https://example.org filters: - MapRequestHeader=Blue, X-Request-Red ``` -------------------------------- ### Example Response for a Particular Route Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc This JSON object shows the response format for retrieving a specific route by its ID. It details the route_id, predicate, filters, uri, and order. ```json { "route_id": "first_route", "predicate": "(Paths: [/first], match trailing slash: true)", "filters": [], "uri": "https://www.uri-destination.org", "order": 0 } ``` -------------------------------- ### Configure Route with Before Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/writing-custom-predicates-and-filters.adoc Use the `before()` method to apply a filter function that modifies the request before it's processed. This example adds a URI and a custom header. ```java import static SampleBeforeFilterFunctions.instrument; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction instrumentRoute() { return route("instrument_route").GET("/**", http()) .before(uri("https://example.org")) .before(instrument("X-Request-Id")) .build(); } } ``` -------------------------------- ### Implement Custom Global Pre-Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/developer-guide.adoc Implement the GlobalFilter interface as a bean to apply a filter to all requests. This example demonstrates adding a custom header to the proxied request. ```java @Bean public GlobalFilter customGlobalFilter() { return (exchange, chain) -> exchange.getPrincipal() .map(Principal::getName) .defaultIfEmpty("Default User") .map(userName -> { //adds header to proxied request ServerHttpRequest.Builder builder = exchange.getRequest().mutate().header("CUSTOM-REQUEST-HEADER", userName); //use builder to manipulate the request return exchange.mutate().request(builder.build()).build(); }) .flatMap(chain::filter); } ``` -------------------------------- ### Configure Method Route Predicate Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc Use the Method Route Predicate Factory to match requests based on HTTP methods like GET or POST. Configure this in application.yml. ```yaml spring: cloud: gateway: server: webflux: routes: - id: method_route uri: https://example.org predicates: - Method=GET,POST ``` -------------------------------- ### Configure API Version Strategy with Header, Query, and Media Type Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc This example configures how Spring Cloud Gateway extracts API versions from incoming requests using HTTP headers, query parameters, or media type parameters. ```yaml spring: webflux: apiversion: use: header: X-API-Version # extract version from this header query-parameter: apiVersion # or from this query parameter media-type-parameter: # or from the named media-type parameter "[application/json]": version required: false # allow requests without an explicit version ``` -------------------------------- ### Configure Gateway Routes with Shortcut Notation Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/configuration.adoc Demonstrates equivalent configuration using standard and shortcut notation for route filters. ```yaml spring: cloud: gateway: server: webflux: routes: - id: setstatus_route uri: https://example.org filters: - name: SetStatus args: status: 401 - id: setstatusshortcut_route uri: https://example.org filters: - SetStatus=401 ``` -------------------------------- ### Get a Particular Route Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Displays information about a particular route by making a GET request to `/actuator/gateway/routes/{id}`. ```APIDOC ## GET /actuator/gateway/routes/{id} ### Description Retrieves detailed information about a specific route identified by its ID. ### Method GET ### Endpoint /actuator/gateway/routes/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the route to retrieve. ### Response #### Success Response (200 OK) Returns a JSON object representing the route, including its `predicate`, `filters`, `uri`, and `order`. ``` -------------------------------- ### Invoke Uppercase Function with GET Request Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/java-routes-api.adoc Use a GET request to invoke the uppercase function. The string to be processed is passed as a path parameter. ```bash $ curl http://localhost:8080/uppercase/hello ``` -------------------------------- ### Custom Remote Address Resolver with XForwardedRemoteAddressResolver Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc Demonstrates configuring a custom RemoteAddressResolver using XForwardedRemoteAddressResolver to handle proxied requests. This example uses the maxTrustedIndex to determine the trusted IP address from the X-Forwarded-For header. ```java RemoteAddressResolver resolver = XForwardedRemoteAddressResolver .maxTrustedIndex(1); ... .route("direct-route", r -> r.remoteAddr("10.1.1.1", "10.10.1.1/24") .uri("https://downstream1") .route("proxied-route", r -> r.remoteAddr(resolver, "10.10.1.1", "10.10.1.1/24") .uri("https://downstream2") ) ``` -------------------------------- ### Generate Documentation with Antora Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/README.adoc Build the documentation site for Spring Cloud Gateway using Antora. This command activates the 'docs' profile and runs the Antora plugin. ```bash ./mvnw -pl docs -P docs antora:antora ``` -------------------------------- ### Example Response for Route Filters Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc This JSON structure shows an example response when requesting route filters. Note that the null value indicates an incomplete implementation of the endpoint controller. ```json { "[AddRequestHeaderGatewayFilterFactory@570ed9c configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null, "[SecureHeadersGatewayFilterFactory@fceab5d configClass = Object]": null, "[SaveSessionGatewayFilterFactory@4449b273 configClass = Object]": null } ``` -------------------------------- ### Retrieve a Particular Route Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc To get information about a single route, make a GET request to /actuator/gateway/routes/{id}, replacing {id} with the route's ID. The response provides details for the specified route. ```http GET /actuator/gateway/routes/first_route ``` -------------------------------- ### Configure Routes for Spring Cloud Gateway Server WebFlux Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/src/main/asciidoc/sagan-index.adoc Defines various routes with different predicates and filters, including path matching, host matching, path rewriting, circuit breaker integration, and rate limiting. Requires the `spring-cloud-starter-gateway-server-webflux` dependency. ```java @SpringBootApplication public class DemogatewayApplication { @Bean public RouteLocator customRouteLocator(RouteLocatorBuilder builder) { return builder.routes() .route("path_route", r -> r.path("/get") .uri("https://httpbin.org")) .route("host_route", r -> r.host("*.myhost.org") .uri("https://httpbin.org")) .route("rewrite_route", r -> r.host("*.rewrite.org") .filters(f -> f.rewritePath("/foo/(?.*)", "/${segment}")) .uri("https://httpbin.org")) .route("circuit_breaker_route", r -> r.host("*.circuitbreaker.org") .filters(f -> f.circuitBreaker(c -> c.setName("slowcmd"))) .uri("https://httpbin.org")) .route("circuit_breaker_fallback_route", r -> r.host("*.circuitbreakerfallback.org") .filters(f -> f.circuitBreaker(c -> c.setName("slowcmd").setFallbackUri("forward:/circuitbrekerfallback"))) .uri("https://httpbin.org")) .route("limit_route", r -> r .host("*.limited.org").and().path("/anything/**") .filters(f -> f.requestRateLimiter(c -> c.setRateLimiter(redisRateLimiter()))) .uri("https://httpbin.org")) .build(); } } ``` -------------------------------- ### GET /uppercase/{value} Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/java-routes-api.adoc Invokes the uppercase function by passing the string as a path parameter. ```APIDOC ## GET /uppercase/{value} ### Description Invokes the `uppercase` function with the provided string value. ### Method GET ### Endpoint `/uppercase/{value}` ### Parameters #### Path Parameters - **value** (string) - Required - The string to be converted to uppercase. ### Response #### Success Response (200) - **body** (string) - The uppercase version of the input string. ### Response Example ``` HELLO ``` ``` -------------------------------- ### Configure PreserveHostHeader GatewayFilter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/preservehostheader-factory.adoc Example configuration for the PreserveHostHeader filter within an application.yml file. ```yaml spring: cloud: gateway: server: webflux: routes: - id: preserve_host_route uri: https://example.org filters: - PreserveHostHeader ``` -------------------------------- ### Enable and Configure Permissions-Policy Globally Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/secureheaders-factory.adoc Opt in to add the `Permissions-Policy` header globally and configure its directives, such as `geolocation`. ```yaml spring: cloud: gateway: filter: secure-headers: enable: permissions-policy permissions-policy : geolocation=(self "https://example.com") ``` -------------------------------- ### Configure Remote Address Resolver with Java Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/gateway-request-predicates.adoc Demonstrates how to configure a custom RemoteAddressResolver using Java, specifically the XForwardedRemoteAddressResolver, to handle requests behind a proxy. ```java RemoteAddressResolver resolver = XForwardedRemoteAddressResolver .maxTrustedIndex(1); ... .route("direct-route", r -> r.remoteAddr("10.1.1.1", "10.10.1.1/24") .uri("https://downstream1") .route("proxied-route", r -> r.remoteAddr(resolver, "10.10.1.1", "10.10.1.1/24") .uri("https://downstream2") ) ``` -------------------------------- ### Create a Route Definition Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Creates a new route definition by making a POST request to `/actuator/gateway/routes/{id_route_to_create}`. Predicates and filters must be provided as shortcut DSL strings. A successful creation returns `201 Created`. After creation, call `POST /actuator/gateway/refresh` to apply the change. ```APIDOC ## POST /actuator/gateway/routes/{id_route_to_create} ### Description Creates a new route definition. Routes defined in application configuration are read-only and cannot be modified or deleted via this endpoint. ### Method POST ### Endpoint /actuator/gateway/routes/{id_route_to_create} ### Parameters #### Path Parameters - **id_route_to_create** (string) - Required - The ID of the route to create. #### Request Body - **predicates** (Array) - Required - The route predicates in shortcut DSL string format (e.g., `"Path=/foo/**"`). - **filters** (Array) - Required - The route filters in shortcut DSL string format (e.g., `"StripPrefix=1"`). - **uri** (string) - Required - The destination URI of the route. - **order** (number) - Optional - The route order. ### Request Example ```json { "predicates": ["Path=/mypath/**", "Weight=mygroup,20"], "filters": ["StripPrefix=1"], "uri": "http://backend-service:8080", "order": 0 } ``` ### Response #### Success Response (201 Created) Indicates successful creation of the route. #### Error Response - **404 Not Found**: If attempting to modify a configuration-defined route. - **500 Internal Server Error**: If duplicating a route definition by POSTing to an existing ID without deleting it first. ``` -------------------------------- ### Configure RewriteLocationResponseHeader Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/rewritelocationresponseheader.adoc Examples of configuring the RewriteLocationResponseHeader filter using YAML and Java DSL. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: rewritelocationresponseheader_route uri: http://example.org predicates: - Path=/** filters: - RewriteLocationResponseHeader=AS_IN_REQUEST, Location, , ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.filter.RewriteLocationResponseHeaderFilterFunctions.rewriteLocationResponseHeader; import static org.springframework.cloud.gateway.server.mvc.filter.RewriteLocationResponseHeaderFilterFunctions.StripVersion; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsRewriteLocationResponseHeader() { return route("rewritelocationresponseheader_route") .GET("/**", http()) .before(uri("https://example.org")) .after(rewriteLocationResponseHeader(config -> config.setLocationHeaderName("Location") .setStripVersion(StripVersion.AS_IN_REQUEST))) .build(); } } ``` -------------------------------- ### Configure DedupeResponseHeader Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/deduperesponseheader.adoc Examples of configuring the DedupeResponseHeader filter using YAML and Java DSL. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: dedupe_response_header_route uri: https://example.org predicates: - Path=/hello filters: - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.dedupeResponseHeader; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; import static org.springframework.web.servlet.function.RequestPredicates.path; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsDedupeResponseHeader() { return route("dedupe_response_header_route") .route(path("/hello"), http()) .before(uri("https://example.org")) .after(dedupeResponseHeader("Access-Control-Allow-Credentials Access-Control-Allow-Origin")) .build(); } } ``` -------------------------------- ### Retrieve Global Filters Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Make a GET request to /actuator/gateway/globalfilters to retrieve the global filters applied to all routes. ```json { "org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter@77856cc5": 10100, "org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@4f6fd101": 10000, "org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@32d22650": -1, "org.springframework.cloud.gateway.filter.ForwardRoutingFilter@106459d9": 2147483647, "org.springframework.cloud.gateway.filter.NettyRoutingFilter@1fbd5e0": 2147483647, "org.springframework.cloud.gateway.filter.ForwardPathFilter@33a71d23": 0, "org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@135064ea": 2147483637, "org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@23c05889": 2147483646 } ``` -------------------------------- ### Configure RemoveRequestParameter Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/removerequestparameter.adoc Examples showing how to configure the RemoveRequestParameter filter using YAML and Java DSL. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: removerequestparameter_route uri: https://example.org predicates: - Path=/** filters: - RemoveRequestParameter=red ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.removeRequestParameter; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsRemoveRequestParameter() { return route("removerequestparameter_route") .GET("/**", http()) .before(uri("https://example.org")) .before(removeRequestParameter("red")) .build(); } } ``` -------------------------------- ### Version Predicate in Java DSL Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/gateway-request-predicates.adoc Demonstrates using the Version predicate in the Java DSL for configuring routes. Requires importing static methods for route, version, and http. ```java import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.version; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctions() { return route("version_13_route") .route(version("1.3"), http()) .before(uri("https://example.org")) .build(); } } ``` -------------------------------- ### Get Route Filters Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Retrieves the GatewayFilter factories applied to routes. The response provides a string representation of each factory. ```APIDOC ## GET /actuator/gateway/routefilters ### Description Retrieves the `GatewayFilter` factories applied to routes. The response contains a string representation of each factory object. ### Method GET ### Endpoint /actuator/gateway/routefilters ### Response #### Success Response (200) - **(string)** - A string representation of the `GatewayFilter` factory object. ### Response Example { "[AddRequestHeaderGatewayFilterFactory@570ed9c configClass = AbstractNameValueGatewayFilterFactory.NameValueConfig]": null, "[SecureHeadersGatewayFilterFactory@fceab5d configClass = Object]": null, "[SaveSessionGatewayFilterFactory@4449b273 configClass = Object]": null } ``` -------------------------------- ### Download EditorConfig and Spring Format Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/README.adoc Fetches default formatting configuration files from the Spring Cloud build repository. Ensures consistent code style across the project. ```bash $ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/.editorconfig -o .editorconfig $ touch .springformat ``` -------------------------------- ### Configure Routes for Spring Cloud Gateway Server Web MVC Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/src/main/asciidoc/sagan-index.adoc Configures routes using the Spring Cloud Gateway Server MVC API, demonstrating path, host, rewrite, circuit breaker, and rate limiting configurations. Requires the `spring-cloud-starter-gateway-server-webmvc` dependency. ```java import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.*; import static org.springframework.cloud.gateway.server.mvc.predicate.GatewayRequestPredicates.*; //... @SpringBootApplication public class DemogatewayApplication { @Bean public RouterFunction customRoutes() { // @formatter:off return route("path_route") .GET("/get", http()) .before(uri("https://httpbin.org")) .build().and(route("host_route") .route(host("*.myhost.org"), http()) .before(uri("https://httpbin.org")) .build().and(route("rewrite_route") .route(host("*.rewrite.org"), http()) .before(uri("https://httpbin.org")) .before(rewritePath("/foo/(?.*)", "/${segment}")) .build().and(route("circuitbreaker_route") .route(host("*.circuitbreaker.org"), http()) .before(uri("https://httpbin.org")) .filter(circuitBreaker("slowcmd")) .build().and(route("circuitbreaker_fallback_route") .route(host("*.circuitbreakerfallback.org"), http()) .before(uri("https://httpbin.org")) .filter(circuitBreaker(c -> c.setId("slowcmd").setFallbackUri("forward:/fallback"))) .build().and(route("limit_route") .route(host("*.limited.org").and(path("/anything/**")), http()) .before(uri("https://httpbin.org")) .filter(rateLimit(c -> c.setCapacity(10).setPeriod(Duration.ofSeconds(1)).setKeyResolver(request -> request.headers().firstHeader("X-TokenId")))) .build()))))); // @formatter:on } } ``` -------------------------------- ### Configure DiscoveryClient Routes in application.yml Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/the-discoveryclient-route-definition-locator.adoc This snippet demonstrates how to enable and customize predicates and filters for DiscoveryClient routes using application.yml. It includes custom Host and Path predicates, along with CircuitBreaker and RewritePath filters. ```yaml spring: cloud: gateway: discovery: locator: predicates: - name: Host args: pattern: "'**.foo.com'" - name: Path args: pattern: "'/' + serviceId + '/**'" filters: - name: CircuitBreaker args: name: serviceId - name: RewritePath args: regexp: "'/' + serviceId + '/?(?.*)'" replacement: "'/${remaining}'" ``` -------------------------------- ### Configure TokenRelay with clientRegistrationId in YAML Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/tokenrelay-factory.adoc This YAML configuration achieves the same as the Java example, specifying a `clientRegistrationId` for token relay. ```yaml spring: cloud: gateway: server: webflux: routes: - id: resource uri: http://localhost:9000 predicates: - Path=/resource filters: - TokenRelay=myregistrationid ``` -------------------------------- ### Configure DiscoveryClient Routes in application.properties Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/the-discoveryclient-route-definition-locator.adoc This snippet shows how to enable and customize predicates and filters for DiscoveryClient routes using application.properties. It includes custom Path and Host predicates, along with CircuitBreaker and RewritePath filters. ```properties spring.cloud.gateway.discovery.locator.predicates[0].name=Path spring.cloud.gateway.discovery.locator.predicates[0].args[pattern]="'/'+serviceId+'/**'" spring.cloud.gateway.discovery.locator.predicates[1].name=Host spring.cloud.gateway.discovery.locator.predicates[1].args[pattern]="'**.foo.com'" spring.cloud.gateway.discovery.locator.filters[0].name=CircuitBreaker spring.cloud.gateway.discovery.locator.filters[0].args[name]=serviceId spring.cloud.gateway.discovery.locator.filters[1].name=RewritePath spring.cloud.gateway.discovery.locator.filters[1].args[regexp]="'/' + serviceId + '/?(?.*)'" spring.cloud.gateway.discovery.locator.filters[1].args[replacement]="'/${remaining}'" ``` -------------------------------- ### RequestSize Error Message Format Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/requestsize-factory.adoc Example of the errorMessage header returned when a request exceeds the configured size limit. ```text errorMessage : Request size is larger than permissible limit. Request size is 6.0 MB where permissible limit is 5.0 MB ``` -------------------------------- ### Retry GatewayFilter with Shortcut Notation Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/gatewayfilter-factories/retry-factory.adoc Demonstrates the equivalent configuration of the Retry GatewayFilter using a simplified shortcut notation for status and method. ```yaml spring: cloud: gateway: server: webflux: routes: - id: retry_route uri: https://example.org filters: - name: Retry args: retries: 3 statuses: INTERNAL_SERVER_ERROR methods: GET backoff: firstBackoff: 10ms maxBackoff: 50ms factor: 2 basedOnPreviousValue: false jitter: randomFactor: 0.5 timeout: 100ms - id: retryshortcut_route uri: https://example.org filters: - Retry=3,INTERNAL_SERVER_ERROR,GET,10ms,50ms,2,false,0.5,100ms ``` -------------------------------- ### Configure RemoveResponseHeader Filter Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/filters/removeresponseheader.adoc Examples showing how to apply the RemoveResponseHeader filter to a route using YAML configuration and the Java DSL. ```yaml spring: cloud: gateway: server: webmvc: routes: - id: removeresponseheader_route uri: https://example.org predicates: - Path=/anything/removeresponseheader filters: - RemoveResponseHeader=X-Response-Foo ``` ```java import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.uri; import static org.springframework.cloud.gateway.server.mvc.filter.AfterFilterFunctions.removeResponseHeader; import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route; import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http; @Configuration class RouteConfiguration { @Bean public RouterFunction gatewayRouterFunctionsRemoveResponseHeader() { return route("removeresponseheader_route") .GET("/anything/removeresponseheader", http()) .before(uri("https://example.org")) .after(removeResponseHeader("X-Response-Foo")) .build(); } } ``` -------------------------------- ### Get Route by ID Source: https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/actuator-api.adoc Retrieves information about a specific route identified by its ID. The response includes the route's configuration details. ```APIDOC ## GET /actuator/gateway/routes/{id} ### Description Retrieves information about a single route identified by its ID. The response includes the route's configuration details such as ID, predicates, filters, URI, and order. ### Method GET ### Endpoint /actuator/gateway/routes/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the route to retrieve. ### Response #### Success Response (200) - **route_id** (string) - The route ID. - **predicate** (string) - A human-readable string representation of the route predicates. - **filters** (Array) - The `GatewayFilter` factories applied to the route. - **uri** (string) - The destination URI of the route. - **order** (Number) - The route order. ### Response Example { "route_id": "first_route", "predicate": "(Paths: [/first], match trailing slash: true)", "filters": [], "uri": "https://www.uri-destination.org", "order": 0 } ```