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 cookieName,
String... cookieValues)
Add the given header to all requests that haven't added it.
|
WebClient.Builder |
defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Manipulate the default cookies with the given consumer.
|
WebClient.Builder |
defaultHeader(String headerName,
String... headerValues)
Add the given header to all requests that have not added it.
|
WebClient.Builder |
defaultHeaders(Consumer<HttpHeaders> headersConsumer)
Manipulate the default headers with the given consumer.
|
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(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) .exchange() .then(response -> response.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()) .exchange() .then(response -> response.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") .exchange() .then(response -> response.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()) .exchange() .then(response -> response.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 headerName, String... headerValues)
headerName
- the header nameheaderValues
- the header valuesWebClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer)
HttpHeaders
methods.headersConsumer
- a function that consumes the HttpHeaders
WebClient.Builder defaultCookie(String cookieName, String... cookieValues)
cookieName
- the cookie namecookieValues
- the cookie valuesWebClient.Builder defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
MultiValueMap
methods.cookiesConsumer
- a function that consumes the cookies mapWebClient.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.
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 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
.