You can use UriComponentsBuilder to build an URI :
URI uri = UriComponentsBuilder.fromHttpUrl("https://example.com/mypage").path("/{id}.xml").build(id); myWebClient.get() .uri(uri) .header(AUTHORIZATION, getAuthorizationHeaderValue(username, password)) ....
Alternatively, if the HTTP requests that you need to sent out have some common settings(i.e. base url and Authorization header in your case) , you can configure them at the WebClient.Builder level. The WebClient build by this builder will be configured with these common setting by default such that you do not need to configure them again and again for each HTTP request. Something like:
@Component public class ExampleComClient { private final WebClient webClient; @Autowired public ExampleComClient(WebClient.Builder builder) { this.webClient = builder.baseUrl("https://example.com/mypage") .defaultHeader(AUTHORIZATION, getAuthorizationHeaderValue(username, password)) .build(); } public String getById(Integer id){ return webClient.get() .uri(uriBuilder -> uriBuilder.path("/{id}.xml").build(id)) .accept(MediaType.TEXT_XML) .retrieve() .bodyToMono(String.class) .block(); } public String getByName(String name){ return webClient.get() .uri(uriBuilder -> uriBuilder.queryParam("name",name).build()) .accept(MediaType.TEXT_XML) .retrieve() .bodyToMono(String.class) .block(); } }