Interface RestClient.Builder
- Enclosing interface:
- RestClient
RestClient.- 
Method SummaryModifier and TypeMethodDescriptionapply(Consumer<RestClient.Builder> builderConsumer) Apply the givenConsumerto this builder instance.Configure a base URL for requests.Configure a baseURIfor requests.build()Build theRestClientinstance.clone()Clone thisRestClient.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.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) Provide a consumer to access to every default header declared so far, with the possibility to add, replace, or remove.defaultRequest(Consumer<RestClient.RequestHeadersSpec<?>> defaultRequest) Provide a consumer to customize every request being built.defaultStatusHandler(Predicate<HttpStatusCode> statusPredicate, RestClient.ResponseSpec.ErrorHandler errorHandler) Register a default status handler to apply to every response.defaultStatusHandler(ResponseErrorHandler errorHandler) Register a default status handler to apply to every response.defaultUriVariables(Map<String, ?> defaultUriVariables) Configure default URL variable values to use when expanding URI templates with aMap.messageConverters(Consumer<List<HttpMessageConverter<?>>> configurer) Configure the message converters for theRestClientto use.messageConverters(List<HttpMessageConverter<?>> messageConverters) Set the message converters for theRestClientto use.observationConvention(ClientRequestObservationConvention observationConvention) Configure theObservationConventionto use for collecting metadata for the request observation.observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Configure theObservationRegistryto use for recording HTTP client observations.requestFactory(ClientHttpRequestFactory requestFactory) Configure theClientHttpRequestFactoryto use.requestInitializer(ClientHttpRequestInitializer initializer) Add the given request initializer to the end of the initializer chain.requestInitializers(Consumer<List<ClientHttpRequestInitializer>> initializersConsumer) Manipulate the initializers with the given consumer.requestInterceptor(ClientHttpRequestInterceptor interceptor) Add the given request interceptor to the end of the interceptor chain.requestInterceptors(Consumer<List<ClientHttpRequestInterceptor>> interceptorsConsumer) Manipulate the interceptors with the given consumer.uriBuilderFactory(UriBuilderFactory uriBuilderFactory) Provide a pre-configuredUriBuilderFactoryinstance.
- 
Method Details- 
baseUrlConfigure a base URL for requests. Effectively a shortcut for:String baseUrl = "https://abc.go.com/v1"; DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl); RestClient client = RestClient.builder().uriBuilderFactory(factory).build(); The DefaultUriBuilderFactoryis 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, thebaseUrlvalue provided here will be ignored.- Returns:
- this builder
- See Also:
 
- 
baseUrlConfigure a baseURIfor requests. Effectively a shortcut for:URI baseUrl = URI.create("https://abc.go.com/v1"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(baseUrl.toString()); RestClient client = RestClient.builder().uriBuilderFactory(factory).build();The DefaultUriBuilderFactoryis 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, thebaseUrlvalue provided here will be ignored.- Returns:
- this builder
- Since:
- 6.2
- See Also:
 
- 
defaultUriVariablesConfigure 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); RestClient client = RestClient.builder().uriBuilderFactory(factory).build(); Note: this method is mutually exclusive with uriBuilderFactory(UriBuilderFactory). If both are used, thedefaultUriVariablesvalue provided here will be ignored.- Returns:
- this builder
- See Also:
 
- 
uriBuilderFactoryProvide a pre-configuredUriBuilderFactoryinstance. This is an alternative to, and effectively overrides the following shortcut properties:- Parameters:
- uriBuilderFactory- the URI builder factory to use
- Returns:
- this builder
- See Also:
 
- 
defaultHeaderGlobal 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
- Returns:
- this builder
 
- 
defaultHeadersProvide a consumer to access to every default header declared so far, with the possibility to add, replace, or remove.- Parameters:
- headersConsumer- the consumer
- Returns:
- this builder
 
- 
defaultCookieGlobal 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
- Since:
- 6.2
 
- 
defaultCookiesProvides 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
- Since:
- 6.2
 
- 
defaultRequestProvide a consumer to customize every request being built.- Parameters:
- defaultRequest- the consumer to use for modifying requests
- Returns:
- this builder
 
- 
defaultStatusHandlerRestClient.Builder defaultStatusHandler(Predicate<HttpStatusCode> statusPredicate, RestClient.ResponseSpec.ErrorHandler errorHandler) 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
- errorHandler- handler that typically, though not necessarily, throws an exception
- Returns:
- this builder
 
- 
defaultStatusHandlerRegister 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.The first status handler who claims that a response has an error is invoked. If you want to disable other defaults, consider using defaultStatusHandler(Predicate, ResponseSpec.ErrorHandler)with a predicate that matches all status codes.- Parameters:
- errorHandler- handler that typically, though not necessarily, throws an exception
- Returns:
- this builder
 
- 
requestInterceptorAdd the given request interceptor to the end of the interceptor chain.- Parameters:
- interceptor- the interceptor to be added to the chain
- Returns:
- this builder
 
- 
requestInterceptorsRestClient.Builder requestInterceptors(Consumer<List<ClientHttpRequestInterceptor>> interceptorsConsumer) Manipulate the interceptors with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove interceptors, change ordering, etc.- Parameters:
- interceptorsConsumer- a function that consumes the interceptors list
- Returns:
- this builder
 
- 
requestInitializerAdd the given request initializer to the end of the initializer chain.- Parameters:
- initializer- the initializer to be added to the chain
- Returns:
- this builder
 
- 
requestInitializersRestClient.Builder requestInitializers(Consumer<List<ClientHttpRequestInitializer>> initializersConsumer) Manipulate the initializers with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove initializers, change ordering, etc.- Parameters:
- initializersConsumer- a function that consumes the initializers list
- Returns:
- this builder
 
- 
requestFactoryConfigure theClientHttpRequestFactoryto use. This is useful for plugging in and/or customizing options of the underlying HTTP client library (for example, SSL).If no request factory is specified, RestClientuses Apache Http Client, Jetty Http Client if available on the classpath, and defaults to the JDK HttpClient if thejava.net.httpmodule is loaded, or to a simple default otherwise.- Parameters:
- requestFactory- the request factory to use
- Returns:
- this builder
 
- 
messageConvertersConfigure the message converters for theRestClientto use.- Parameters:
- configurer- the configurer to apply on the list of default- HttpMessageConverterpre-initialized
- Returns:
- this builder
- See Also:
 
- 
messageConvertersSet the message converters for theRestClientto use.- Parameters:
- messageConverters- the list of- HttpMessageConverterto use
- Returns:
- this builder
- Since:
- 6.2
- See Also:
 
- 
observationRegistryRestClient.Builder observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Configure theObservationRegistryto use for recording HTTP client observations.- Parameters:
- observationRegistry- the observation registry to use
- Returns:
- this builder
 
- 
observationConventionConfigure theObservationConventionto use for collecting metadata for the request observation. Will useDefaultClientRequestObservationConventionif none provided.- Parameters:
- observationConvention- the observation convention to use
- Returns:
- this builder
 
- 
applyApply the givenConsumerto this builder instance.This can be useful for applying pre-packaged customizations. - Parameters:
- builderConsumer- the consumer to apply
- Returns:
- this builder
 
- 
cloneRestClient.Builder clone()Clone thisRestClient.Builder.
- 
buildRestClient build()Build theRestClientinstance.
 
-