RestTemplateBuilder
Builder that can be used to configure and create a RestTemplate. Provides convenience methods to register converters, error handlers and UriTemplateHandlers.
By default, the built RestTemplate will attempt to use the most suitable ClientHttpRequestFactory, call detectRequestFactory(false) if you prefer to keep the default. In a typical auto-configured Spring Boot application this builder is available as a bean and can be injected whenever a RestTemplate is needed.
Author
Stephane Nicoll
Phillip Webb
Andy Wilkinson
Brian Clozel
Dmytro Nosan
Kevin Strijbos
Ilya Lukyanovich
Scott Frederick
Yanming Zhou
Since
1.4.0
Constructors
Link copied to clipboard
Create a new RestTemplateBuilder instance.
Functions
Link copied to clipboard
open fun additionalCustomizers(customizers: Collection<out RestTemplateCustomizer>): RestTemplateBuilder
Add RestTemplateCustomizers that should be applied to the RestTemplate.
Link copied to clipboard
open fun additionalInterceptors(interceptors: Collection<out ClientHttpRequestInterceptor>): RestTemplateBuilder
open fun additionalInterceptors(interceptors: Array<ClientHttpRequestInterceptor>): RestTemplateBuilder
Add additional ClientHttpRequestInterceptors that should be used with the RestTemplate.
Link copied to clipboard
open fun additionalMessageConverters(messageConverters: Collection<out HttpMessageConverter<out Any>>): RestTemplateBuilder
open fun additionalMessageConverters(messageConverters: Array<HttpMessageConverter<out Any>>): RestTemplateBuilder
Add additional HttpMessageConverters that should be used with the RestTemplate.
Link copied to clipboard
open fun additionalRequestCustomizers(requestCustomizers: Collection<out RestTemplateRequestCustomizer<out Any>>): RestTemplateBuilder
open fun additionalRequestCustomizers(requestCustomizers: Array<RestTemplateRequestCustomizer<out Any>>): RestTemplateBuilder
Add the RestTemplateRequestCustomizers that should be applied to the ClientHttpRequest.
Link copied to clipboard
open fun basicAuthentication(username: String, password: String, charset: Charset): RestTemplateBuilder
Add HTTP Basic Authentication to requests with the given username/password pair, unless a custom Authorization header has been set before.
Link copied to clipboard
Build a new RestTemplate instance and configure it using this builder.
Build a new RestTemplate instance of the specified type and configure it using this builder.
Link copied to clipboard
Build a new ClientHttpRequestFactory instance using the settings of this builder.
Link copied to clipboard
Configure the provided RestTemplate instance using this builder.
Link copied to clipboard
Sets the connection timeout on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Set the RestTemplateCustomizers that should be applied to the RestTemplate.
Link copied to clipboard
Add a default header that will be set if not already present on the outgoing ClientHttpRequest.
Link copied to clipboard
Set the HttpMessageConverters that should be used with the RestTemplate to the default set.
Link copied to clipboard
Set if the ClientHttpRequestFactory should be detected based on the classpath.
Link copied to clipboard
Set the ResponseErrorHandler that should be used with the RestTemplate.
Link copied to clipboard
Set the ClientHttpRequestInterceptors that should be used with the RestTemplate.
Link copied to clipboard
open fun messageConverters(messageConverters: Collection<out HttpMessageConverter<out Any>>): RestTemplateBuilder
open fun messageConverters(messageConverters: Array<HttpMessageConverter<out Any>>): RestTemplateBuilder
Set the HttpMessageConverters that should be used with the RestTemplate.
Link copied to clipboard
Sets the read timeout on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Sets the redirect strategy on the underlying ClientHttpRequestFactory.
Link copied to clipboard
open fun requestCustomizers(requestCustomizers: Collection<out RestTemplateRequestCustomizer<out Any>>): RestTemplateBuilder
open fun requestCustomizers(requestCustomizers: Array<RestTemplateRequestCustomizer<out Any>>): RestTemplateBuilder
Set the RestTemplateRequestCustomizers that should be applied to the ClientHttpRequest.
Link copied to clipboard
open fun requestFactory(requestFactoryType: Class<out ClientHttpRequestFactory>): RestTemplateBuilder
Set the ClientHttpRequestFactory class that should be used with the RestTemplate.
open fun requestFactory(requestFactoryFunction: (ClientHttpRequestFactorySettings) -> ClientHttpRequestFactory): RestTemplateBuilder
Set the request factory function that should be called to provide a ClientHttpRequestFactory each time we build a new RestTemplate instance.
open fun requestFactory(requestFactorySupplier: Supplier<ClientHttpRequestFactory>): RestTemplateBuilder
Set the
Supplier
of ClientHttpRequestFactory that should be called each time we build a new RestTemplate instance.Link copied to clipboard
open fun requestFactoryBuilder(requestFactoryBuilder: ClientHttpRequestFactoryBuilder<out Any>): RestTemplateBuilder
Set the ClientHttpRequestFactoryBuilder that should be used each time we build a new RestTemplate instance.
Link copied to clipboard
open fun requestFactorySettings(requestFactorySettingsCustomizer: UnaryOperator<ClientHttpRequestFactorySettings>): RestTemplateBuilder
Update the ClientHttpRequestFactorySettings using the given customizer.
open fun requestFactorySettings(requestFactorySettings: ClientHttpRequestFactorySettings): RestTemplateBuilder
Sets the ClientHttpRequestFactorySettings.
Link copied to clipboard
Set a root URL that should be applied to each request that starts with
'/'
.Link copied to clipboard
Sets the connection timeout on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Sets the read timeout on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Sets the SSL bundle on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Sets the SSL bundle on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Set the UriTemplateHandler that should be used with the RestTemplate.