Skip to content

Commit

Permalink
WebClient uri method with uriTemplate and UriBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeoffrey Haeyaert authored and rstoyanchev committed Apr 4, 2019
1 parent ed70978 commit 9976783
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
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

0 comments on commit 9976783

Please sign in to comment.