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
constructor(customizers: Array<RestTemplateCustomizer>)
Create a new RestTemplateBuilder instance.

Functions

Link copied to clipboard
Add additional HttpMessageConverters that should be used with the RestTemplate.
Link copied to clipboard
open fun basicAuthentication(username: String, password: String): RestTemplateBuilder
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
open fun build(): RestTemplate
Build a new RestTemplate instance and configure it using this builder.
open fun <T : RestTemplate?> build(restTemplateClass: Class<T>): T
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
open fun <T : RestTemplate?> configure(restTemplate: T): T
Configure the provided RestTemplate instance using this builder.
Link copied to clipboard
open fun connectTimeout(connectTimeout: Duration): RestTemplateBuilder
Sets the connection timeout on the underlying ClientHttpRequestFactory.
Link copied to clipboard
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
open fun detectRequestFactory(detectRequestFactory: Boolean): RestTemplateBuilder
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
Link copied to clipboard
Set the HttpMessageConverters that should be used with the RestTemplate.
Link copied to clipboard
open fun readTimeout(readTimeout: Duration): RestTemplateBuilder
Sets the read timeout on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Sets the redirect strategy on the underlying ClientHttpRequestFactory.
Link copied to clipboard
Link copied to clipboard
Set the ClientHttpRequestFactory class that should be used with the RestTemplate.
Set the request factory function that should be called to provide a ClientHttpRequestFactory each time we build a new RestTemplate instance.
Set the Supplier of ClientHttpRequestFactory that should be called each time we build a new RestTemplate instance.
Link copied to clipboard
Set the ClientHttpRequestFactoryBuilder that should be used each time we build a new RestTemplate instance.
Link copied to clipboard
open fun rootUri(rootUri: String): RestTemplateBuilder
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.