Interface WebClient.Builder
- Enclosing interface:
- WebClient
WebClient
.-
Method Summary
Modifier and TypeMethodDescriptionapply
(Consumer<WebClient.Builder> builderConsumer) Apply the givenConsumer
to this builder instance.Configure a base URL for requests.build()
Builder theWebClient
instance.clientConnector
(ClientHttpConnector connector) Configure theClientHttpConnector
to use.clone()
Clone thisWebClient.Builder
.codecs
(Consumer<ClientCodecConfigurer> configurer) 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.defaultCookies
(Consumer<MultiValueMap<String, String>> cookiesConsumer) Provides access to everydefaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove.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.defaultHeaders
(Consumer<HttpHeaders> headersConsumer) Provides access to everydefaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove.defaultRequest
(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest) Provide a consumer to customize every request being built.defaultUriVariables
(Map<String, ?> defaultUriVariables) Configure default URL variable values to use when expanding URI templates with aMap
.exchangeFunction
(ExchangeFunction exchangeFunction) exchangeStrategies
(Consumer<ExchangeStrategies.Builder> configurer) Deprecated.exchangeStrategies
(ExchangeStrategies strategies) Configure theExchangeStrategies
to use.filter
(ExchangeFilterFunction filter) Add the given filter to the end of the filter chain.filters
(Consumer<List<ExchangeFilterFunction>> filtersConsumer) Manipulate the filters with the given consumer.uriBuilderFactory
(UriBuilderFactory uriBuilderFactory) Provide a pre-configuredUriBuilderFactory
instance.
-
Method Details
-
baseUrl
Configure a base URL for requests. Effectively a shortcut for:String baseUrl = "https://abc.go.com/v1"; DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl); WebClient client = WebClient.builder().uriBuilderFactory(factory).build();
The
DefaultUriBuilderFactory
is used to prepare the URL for every request with the given base URL, unless the URL request for a given URL is absolute in which case the base URL is ignored.Note: this method is mutually exclusive with
uriBuilderFactory(UriBuilderFactory)
. If both are used, the baseUrl value provided here will be ignored. -
defaultUriVariables
Configure default URL variable values to use when expanding URI templates with aMap
. Effectively a shortcut for:Map<String, ?> defaultVars = ...; DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setDefaultVariables(defaultVars); WebClient client = WebClient.builder().uriBuilderFactory(factory).build();
Note: this method is mutually exclusive with
uriBuilderFactory(UriBuilderFactory)
. If both are used, the defaultUriVariables value provided here will be ignored. -
uriBuilderFactory
Provide a pre-configuredUriBuilderFactory
instance. This is an alternative to, and effectively overrides the following shortcut properties:- Parameters:
uriBuilderFactory
- the URI builder factory to use- See Also:
-
defaultHeader
Global option to specify a header to be added to every request, if the request does not already contain such a header.- Parameters:
header
- the header namevalues
- the header values
-
defaultHeaders
Provides access to everydefaultHeader(String, String...)
declared so far with the possibility to add, replace, or remove.- Parameters:
headersConsumer
- the consumer
-
defaultCookie
Global option to specify a cookie to be added to every request, if the request does not already contain such a cookie.- Parameters:
cookie
- the cookie namevalues
- the cookie values
-
defaultCookies
Provides access to everydefaultCookie(String, String...)
declared so far with the possibility to add, replace, or remove.- Parameters:
cookiesConsumer
- a function that consumes the cookies map
-
defaultRequest
Provide a consumer to customize every request being built.- Parameters:
defaultRequest
- the consumer to use for modifying requests- Since:
- 5.1
-
filter
Add the given filter to the end of the filter chain.- Parameters:
filter
- the filter to be added to the chain
-
filters
Manipulate the filters with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove filters, change ordering, etc.- Parameters:
filtersConsumer
- a function that consumes the filter list- Returns:
- this builder
-
clientConnector
Configure theClientHttpConnector
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
.- Parameters:
connector
- the connector to use
-
codecs
- Parameters:
configurer
- the configurer to apply- Since:
- 5.1.13
-
exchangeStrategies
Configure theExchangeStrategies
to use.For most cases, prefer using
codecs(Consumer)
which allows customizing the codecs in theExchangeStrategies
rather than replace them. That ensures multiple parties can contribute to codecs configuration.By default this is set to
ExchangeStrategies.withDefaults()
.- Parameters:
strategies
- the strategies to use
-
exchangeStrategies
Deprecated.as of 5.1.13 in favor ofcodecs(Consumer)
Customize the strategies configured viaexchangeStrategies(ExchangeStrategies)
. This method is designed for use in scenarios where multiple parties wish to update theExchangeStrategies
. -
exchangeFunction
Provide anExchangeFunction
pre-configured withClientHttpConnector
andExchangeStrategies
.This is an alternative to, and effectively overrides
clientConnector(org.springframework.http.client.reactive.ClientHttpConnector)
, andexchangeStrategies(ExchangeStrategies)
.- Parameters:
exchangeFunction
- the exchange function to use
-
apply
Apply the givenConsumer
to this builder instance.This can be useful for applying pre-packaged customizations.
- Parameters:
builderConsumer
- the consumer to apply
-
clone
WebClient.Builder clone()Clone thisWebClient.Builder
. -
build
WebClient build()Builder theWebClient
instance.
-
codecs(Consumer)