Skip to content

WebClient option with both URI template and UriBuilder #22705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ public RequestBodySpec uri(String uriTemplate, Map<String, ?> uriVariables) {
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));
}

@Override
public RequestBodySpec uri(String uriTemplate, Function<UriBuilder, URI> uriFunction) {
attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
return uri(uriFunction.apply(uriBuilderFactory.uriString(uriTemplate)));
}

@Override
public RequestBodySpec uri(Function<UriBuilder, URI> uriFunction) {
return uri(uriFunction.apply(uriBuilderFactory.builder()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,16 @@ interface UriSpec<S extends RequestHeadersSpec<?>> {
*/
S uri(String uri, Map<String, ?> uriVariables);

/**
* Build the URI for the request using the {@link UriBuilderFactory}
* configured for this client and initialized with the specified <code>uri</code>.
*/
S uri(String uri, Function<UriBuilder, URI> uriFunction);

/**
* Build the URI for the request using the {@link UriBuilderFactory}
* configured for this client.
* @see #uri(String, Function)
*/
S uri(Function<UriBuilder, URI> uriFunction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public void uriBuilder() {
assertEquals("/base/path?q=12", request.url().toString());
}


@Test
public void uriBuilderWithUriTemplate() {
this.builder.build().get()
.uri("/path/{id}", builder -> builder.queryParam("q", "12").build("identifier"))
.exchange().block(Duration.ofSeconds(10));

ClientRequest request = verifyAndGetRequest();
assertEquals("/base/path/identifier?q=12", request.url().toString());
assertEquals("/path/{id}", request.attribute(WebClient.class.getName() + ".uriTemplate").<String>get());
}

@Test
public void uriBuilderWithPathOverride() {
this.builder.build().get()
Expand Down