PrefixPath Filter

The PrefixPath filter takes a single prefix parameter. The following example configures a PrefixPath filter:

application.yml
spring:
  cloud:
    gateway:
      mvc:
        routes:
        - id: prefixpath_route
          uri: https://example.org
          filters:
          - PrefixPath=/mypath
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.BeforeFilterFunctions.prefixPath;
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<ServerResponse> gatewayRouterFunctionsPrefixPath() {
		return route("prefixpath_route")
				.GET("/**", http("https://example.org"))
					.before("/mypath")
					.build();
    }
}

This prefixes /mypath to the path of all matching requests. So a request to /hello is sent to /mypath/hello.