Class ClientBuilder


public final class ClientBuilder
extends AbstractClientOptionsBuilder
Creates a new client that connects to the specified URI using the builder pattern. Use the factory methods in Clients if you do not have many options to override. If you are creating an WebClient, it is recommended to use the WebClientBuilder or factory methods in WebClient.

How are decorators and HTTP headers configured?

Unlike other options, when a user calls option(ClientOption, Object) or options() with a ClientOptions.DECORATION or a ClientOptions.HEADERS, this builder will not simply replace the old option but merge the specified option into the previous option value. For example:


 ClientOptionsBuilder b = ClientOptions.builder();
 b.option(ClientOption.HEADERS, headersA);
 b.option(ClientOption.HEADERS, headersB);
 b.option(ClientOption.DECORATION, decorationA);
 b.option(ClientOption.DECORATION, decorationB);

 ClientOptions opts = b.build();
 HttpHeaders headers = opts.headers();
 ClientDecoration decorations = opts.decoration();
 
headers will contain all HTTP headers of headersA and headersB. If headersA and headersB have the headers with the same name, the duplicate header in headerB will replace the one with the same name in headerA. Similarly, decorations will contain all decorators of decorationA and decorationB, but there will be no replacement but only addition.