In Spring Cloud API Gateway (MVC), I am trying to filer a GET request that dynamically creates a request param (query string)?
Original request path to API Gateway with path param:
v1/sample-resource/methodName?id=id12345
I would like the filtered request path result to be:
v1/sample-resource/methodName/id12345
Is there any documentation available that shows how to do this? I've seen:
RewritePath Filter
AddRequestParameter Filter
Related dependency versions:
id 'org.springframework.boot' version '3.3.1'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway-mvc'
I tried creating a bean, but don't understand how to obtain the value for addRequestParameter
dynamically and I'm not sure about rewritePath either.
Example
File: com/example/demo/routes/RouteConfiguration.java
@Configuration
class RouteConfiguration {
@Bean
public RouterFunction<ServerResponse> gatewayRouterAddRequestParam() {
return route("add_request_parameter_route")
.GET("v1/resource-name/id12345/methodName", http("https://example.org"))
.before(
rewritePath("v1/resource-name/(?<segment>.*)", "v1/resource-name/methodName")
.andThen(addRequestParameter("id", "id12345"))
)
.build();
}
}