Modifier and Type | Method and Description |
---|---|
WebClient.Builder |
apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
Apply the given
Consumer to this builder instance. |
WebClient.Builder |
baseUrl(java.lang.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(java.lang.String cookie,
java.lang.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(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.String>> cookiesConsumer)
Provides access to every
defaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove. |
WebClient.Builder |
defaultHeader(java.lang.String header,
java.lang.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(java.util.function.Consumer<HttpHeaders> headersConsumer)
Provides access to every
defaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove. |
WebClient.Builder |
defaultRequest(java.util.function.Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
Provide a consumer to modify every request being built just before the
call to
exchange() . |
WebClient.Builder |
defaultUriVariables(java.util.Map<java.lang.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(ExchangeStrategies strategies)
Configure the
ExchangeStrategies to use. |
WebClient.Builder |
filter(ExchangeFilterFunction filter)
Add the given filter to the filter chain.
|
WebClient.Builder |
filters(java.util.function.Consumer<java.util.List<ExchangeFilterFunction>> filtersConsumer)
Manipulate the filters with the given consumer.
|
WebClient.Builder |
uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configured
UriBuilderFactory instance. |
WebClient.Builder baseUrl(java.lang.String baseUrl)
For example given base URL "http://abc.com/v1":
Mono<Account> result = client.get().uri("/accounts/{id}", 43) .retrieve() .bodyToMono(Account.class); // Result: http://abc.com/v1/accounts/43 Flux<Account> result = client.get() .uri(builder -> builder.path("/accounts").queryParam("q", "12").build()) .retrieve() .bodyToFlux(Account.class); // Result: http://abc.com/v1/accounts?q=12
The base URL can be overridden with an absolute URI:
Mono<Account> result = client.get().uri("http://xyz.com/path") .retrieve() .bodyToMono(Account.class); // Result: http://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: http://abc.com/v2/accounts?q=12
WebClient.Builder defaultUriVariables(java.util.Map<java.lang.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(java.lang.String header, java.lang.String... values)
header
- the header namevalues
- the header valuesWebClient.Builder defaultHeaders(java.util.function.Consumer<HttpHeaders> headersConsumer)
defaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove.headersConsumer
- the consumerWebClient.Builder defaultCookie(java.lang.String cookie, java.lang.String... values)
cookie
- the cookie namevalues
- the cookie valuesWebClient.Builder defaultCookies(java.util.function.Consumer<MultiValueMap<java.lang.String,java.lang.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(java.util.function.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(java.util.function.Consumer<java.util.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.
By default this is obtained from ExchangeStrategies.withDefaults()
.
strategies
- the strategies to useWebClient.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 clone()
WebClient.Builder
.WebClient.Builder apply(java.util.function.Consumer<WebClient.Builder> builderConsumer)
Consumer
to this builder instance.
This can be useful for applying pre-packaged customizations.
builderConsumer
- the consumer to apply