Interface WebClient.Builder

Enclosing interface:
WebClient

public static interface WebClient.Builder
A mutable builder for creating a WebClient.
  • Method Details

    • baseUrl

      WebClient.Builder baseUrl(String 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.

      See Also:
    • defaultUriVariables

      WebClient.Builder defaultUriVariables(Map<String,?> defaultUriVariables)
      Configure default URL variable values to use when expanding URI templates with a Map. 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.

      See Also:
    • uriBuilderFactory

      WebClient.Builder uriBuilderFactory(org.springframework.web.util.UriBuilderFactory uriBuilderFactory)
      Provide a pre-configured UriBuilderFactory instance. This is an alternative to, and effectively overrides the following shortcut properties:
      Parameters:
      uriBuilderFactory - the URI builder factory to use
      See Also:
    • defaultHeader

      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.
      Parameters:
      header - the header name
      values - the header values
    • defaultHeaders

      WebClient.Builder defaultHeaders(Consumer<org.springframework.http.HttpHeaders> headersConsumer)
      Provides access to every defaultHeader(String, String...) declared so far with the possibility to add, replace, or remove.
      Parameters:
      headersConsumer - the consumer
    • defaultCookie

      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.
      Parameters:
      cookie - the cookie name
      values - the cookie values
    • defaultCookies

      WebClient.Builder defaultCookies(Consumer<org.springframework.util.MultiValueMap<String,String>> cookiesConsumer)
      Provides access to every defaultCookie(String, String...) declared so far with the possibility to add, replace, or remove.
      Parameters:
      cookiesConsumer - a function that consumes the cookies map
    • defaultRequest

      WebClient.Builder defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> defaultRequest)
      Provide a consumer to customize every request being built.
      Parameters:
      defaultRequest - the consumer to use for modifying requests
      Since:
      5.1
    • defaultStatusHandler

      WebClient.Builder defaultStatusHandler(Predicate<org.springframework.http.HttpStatusCode> statusPredicate, Function<ClientResponse,reactor.core.publisher.Mono<? extends Throwable>> exceptionFunction)
      Register a default status handler to apply to every response. Such default handlers are applied in the order in which they are registered, and after any others that are registered for a specific response.
      Parameters:
      statusPredicate - to match responses with
      exceptionFunction - to map the response to an error signal
      Returns:
      this builder
      Since:
      6.0
    • 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

      WebClient.Builder clientConnector(org.springframework.http.client.reactive.ClientHttpConnector connector)
      Configure the 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.

      Parameters:
      connector - the connector to use
    • codecs

      WebClient.Builder codecs(Consumer<org.springframework.http.codec.ClientCodecConfigurer> configurer)
      Configure the codecs for the WebClient in the underlying ExchangeStrategies.
      Parameters:
      configurer - the configurer to apply
      Since:
      5.1.13
    • exchangeStrategies

      WebClient.Builder exchangeStrategies(ExchangeStrategies strategies)
      Configure the ExchangeStrategies to use.

      For most cases, prefer using codecs(Consumer) which allows customizing the codecs in the ExchangeStrategies 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 of codecs(Consumer)
      Customize the strategies configured via exchangeStrategies(ExchangeStrategies). This method is designed for use in scenarios where multiple parties wish to update the ExchangeStrategies.
    • exchangeFunction

      WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction)
      Provide an ExchangeFunction pre-configured with ClientHttpConnector and ExchangeStrategies.

      This is an alternative to, and effectively overrides clientConnector(org.springframework.http.client.reactive.ClientHttpConnector), and exchangeStrategies(ExchangeStrategies).

      Parameters:
      exchangeFunction - the exchange function to use
    • observationRegistry

      WebClient.Builder observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)
      Provide an ObservationRegistry to use for recording observations for HTTP client calls.
      Parameters:
      observationRegistry - the observation registry to use
      Since:
      6.0
    • observationConvention

      WebClient.Builder observationConvention(ClientRequestObservationConvention observationConvention)
      Provide an ObservationConvention to use for collecting metadata for the request observation. Will use DefaultClientRequestObservationConvention if none provided.
      Parameters:
      observationConvention - the observation convention to use
      Since:
      6.0
    • apply

      WebClient.Builder apply(Consumer<WebClient.Builder> builderConsumer)
      Apply the given Consumer to this builder instance.

      This can be useful for applying pre-packaged customizations.

      Parameters:
      builderConsumer - the consumer to apply
    • clone

      Clone this WebClient.Builder.
    • build

      WebClient build()
      Build the WebClient instance.