Tutorial by Examples

The getForObject and getForEntity methods of RestTemplate load the entire response in memory. This is not suitable for downloading large files since it can cause out of memory exceptions. This example shows how to stream the response of a GET request. RestTemplate restTemplate // = ...; // Optio...
Preemptive basic authentication is the practice of sending http basic authentication credentials (username and password) before a server replies with a 401 response asking for them. This can save a request round trip when consuming REST apis which are known to require basic authentication. As descr...
Using HttpClient as RestTemplate's underlying implementation to create HTTP requests allows for automatic handling of basic authentication requests (an http 401 response) when interacting with APIs. This example shows how to configure a RestTemplate to achieve this. // The credentials are stored he...
The exchange methods of RestTemplate allows you specify a HttpEntity that will be written to the request when execute the method. You can add headers (such user agent, referrer...) to this entity: public void testHeader(final RestTemplate restTemplate){ //Set the headers you need send ...
To let RestTemplate understand generic of returned content we need to define result type reference. org.springframework.core.ParameterizedTypeReference has been introduced since 3.2 Wrapper<Model> response = restClient.exchange(url, HttpMethod.GET, ...

Page 1 of 1