Modifier and Type | Method and Description |
---|---|
WebClient.Builder |
apply(Consumer<WebClient.Builder> builderConsumer)
Apply the given
Consumer to this builder instance. |
WebClient.Builder |
baseUrl(String baseUrl)
Configure a base URL for requests performed through the client.
|
WebClient |
build()
Builder the
WebClient instance. |
WebClient.Builder |
clientConnector(ClientHttpConnector connector)
Configure the
ClientHttpConnector to use. |
WebClient.Builder |
clone()
Clone this
WebClient.Builder . |
WebClient.Builder |
defaultCookie(String cookie,
String... values)
Global option to specify a cookie to be added to every request,
if the request does not already contain such a cookie.
|
WebClient.Builder |
defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Provides access to every
defaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove. |
WebClient.Builder |
defaultHeader(String header,
String... values)
Global option to specify a header to be added to every request,
if the request does not already contain such a header.
|
WebClient.Builder |
defaultHeaders(Consumer<HttpHeaders> headersConsumer)
Provides access to every
defaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove. |
WebClient.Builder |
defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
Provide a consumer to modify every request being built just before the
call to
exchange() . |
WebClient.Builder |
defaultUriVariables(Map<String,?> defaultUriVariables)
Configure default URI variable values that will be used when expanding
URI templates using a
Map . |
WebClient.Builder |
exchangeFunction(ExchangeFunction exchangeFunction)
|
WebClient.Builder |
exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)
Customize the strategies configured via
exchangeStrategies(ExchangeStrategies) . |
WebClient.Builder |
exchangeStrategies(ExchangeStrategies strategies)
Configure the
ExchangeStrategies to use. |
WebClient.Builder |
filter(ExchangeFilterFunction filter)
Add the given filter to the filter chain.
|
WebClient.Builder |
filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)
Manipulate the filters with the given consumer.
|
WebClient.Builder |
uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configured
UriBuilderFactory instance. |
WebClient.Builder baseUrl(String baseUrl)
For example given base URL "https://abc.go.com/v1":
Mono<Account> result = client.get().uri("/accounts/{id}", 43) .retrieve() .bodyToMono(Account.class); // Result: https://abc.go.com/v1/accounts/43 Flux<Account> result = client.get() .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) .retrieve() .bodyToFlux(Account.class); // Result: https://abc.go.com/v1/accounts?q=12
The base URL can be overridden with an absolute URI:
Mono<Account> result = client.get().uri("https://xyz.com/path") .retrieve() .bodyToMono(Account.class); // Result: https://xyz.com/path
Or partially overridden with a UriBuilder
:
Flux<Account> result = client.get() .uri(builder -> builder.replacePath("/v2/accounts").queryParam("q", "12").build()) .retrieve() .bodyToFlux(Account.class); // Result: https://abc.go.com/v2/accounts?q=12
WebClient.Builder defaultUriVariables(Map<String,?> defaultUriVariables)
Map
.defaultUriVariables
- the default values to usebaseUrl(String)
,
uriBuilderFactory(UriBuilderFactory)
WebClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
UriBuilderFactory
instance. This is
an alternative to and effectively overrides the following:
uriBuilderFactory
- the URI builder factory to usebaseUrl(String)
,
defaultUriVariables(Map)
WebClient.Builder defaultHeader(String header, String... values)
header
- the header namevalues
- the header valuesWebClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer)
defaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove.headersConsumer
- the consumerWebClient.Builder defaultCookie(String cookie, String... values)
cookie
- the cookie namevalues
- the cookie valuesWebClient.Builder defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
defaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove.cookiesConsumer
- a function that consumes the cookies mapWebClient.Builder defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
exchange()
.defaultRequest
- the consumer to use for modifying requestsWebClient.Builder filter(ExchangeFilterFunction filter)
filter
- the filter to be added to the chainWebClient.Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)
filtersConsumer
- a function that consumes the filter listWebClient.Builder clientConnector(ClientHttpConnector connector)
ClientHttpConnector
to use. This is useful for
plugging in and/or customizing options of the underlying HTTP client
library (e.g. SSL).
By default this is set to
ReactorClientHttpConnector
.
connector
- the connector to useWebClient.Builder exchangeStrategies(ExchangeStrategies strategies)
ExchangeStrategies
to use.
Note that in a scenario where the builder is configured by
multiple parties, it is preferable to use
exchangeStrategies(Consumer)
in order to customize the same
ExchangeStrategies
. This method here sets the strategies that
everyone else then can customize.
By default this is ExchangeStrategies.withDefaults()
.
strategies
- the strategies to useWebClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)
exchangeStrategies(ExchangeStrategies)
. This method is
designed for use in scenarios where multiple parties wish to update
the ExchangeStrategies
.WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)
ExchangeFunction
pre-configured with
ClientHttpConnector
and ExchangeStrategies
.
This is an alternative to, and effectively overrides
clientConnector(org.springframework.http.client.reactive.ClientHttpConnector)
, and exchangeStrategies(org.springframework.web.reactive.function.client.ExchangeStrategies)
.
exchangeFunction
- the exchange function to useWebClient.Builder apply(Consumer<WebClient.Builder> builderConsumer)
Consumer
to this builder instance.
This can be useful for applying pre-packaged customizations.
builderConsumer
- the consumer to applyWebClient.Builder clone()
WebClient.Builder
.