- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement
Milestone
Description
Toshiaki Maki opened SPR-15124 and commented
In my understanding, when specifying query parameters to WebClient, ClientRequest#method(HttpMethod, URI) or building url string can be used.
I'd like to have more convenient way.
For example, when  http://api.example.com is a externalized property(api.path) and an application accesses $(api.path)/v1/foo?bar=$(bar)&baz=$(baz), we need to write code such as following:
int bar = 100;
String baz = aaa;
ClientRequest<Void> req = ClientRequest
		.method(GET, UriComponentsBuilder.fromHttpUrl(apiPath)
		  .pathSegment("v1", "foo")
		  .queryParam("bar", bar)
		  .queryParam("baz", baz).build().encode().toUri());
// or ClientRequest<Void> req = ClientRequest.GET(apiPath + "/v1/foo?bar=" + bar + "&baz=" + baz);  // I don't like this styleI would like to propose adding the following methods in org.springframework.web.reactive.function.client.ClientRequest
// though rough design
static BodyBuilder method(HttpMethod method, String url,
		Function<UriComponentsBuilder, UriComponents> f) {
	UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
	URI uri = f.apply(builder).toUri();
	return new DefaultClientRequestBuilder(method, uri);
}
static HeadersBuilder<?> GET(String url,
		Function<UriComponentsBuilder, UriComponents> f) {
	return method(HttpMethod.GET, url, f);
}
// POST, PUT, ...With this method, the example code above can be re-written as follows:
ClientRequest<Void> req = ClientRequest
		.GET(apiHost, b -> b.pathSegment("v1", "foo")
                                                 .queryParam("bar", bar)
                                                 .queryParam("baz", baz)
                                                 .build().encode())
		.build();Affects: 5.0 M4
Issue Links:
- RestTemplate drops trailing / from request URI [SPR-15201] #19765 RestTemplate drops trailing / from request URI
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement