Use this tag for Spring's RestTemplate, a class for client-side HTTP communications and RESTful principles enforcement.
The RestTemplate is the central Spring class for client-side HTTP access. Conceptually, it is very similar to the JdbcTemplate, JmsTemplate, and the various other templates found in the Spring Framework and other portfolio projects.
This means, for instance, that the RestTemplate is thread-safe once constructed, and that you can use callbacks to customize its operations.
RestTemplate Methods
-------------------------------------------------------------
| HTTP | RESTTEMPLATE |
-------------------------------------------------------------
| DELETE | delete(String, String...) |
-------------------------------------------------------------
| GET | getForObject(String, Class, String...) |
-------------------------------------------------------------
| HEAD | headForHeaders(String, String...) |
-------------------------------------------------------------
| OPTIONS | optionsForAllow(String, String...) |
-------------------------------------------------------------
| POST | postForLocation(String, Object, String...) |
-------------------------------------------------------------
| PUT | put(String, Object, String...) |
-------------------------------------------------------------
Reference: https://spring.io/blog/2009/03/27/rest-in-spring-3-resttemplate
Error Handling and Customization of Errors
Implement and inject the ResponseErrorHandler interface in a RestTemplate instance – to gracefully handle HTTP errors returned by remote APIs.
By default, the RestTemplate will throw one of these exceptions in case of an HTTP error:
- HttpClientErrorException – in case of HTTP status 4xx
- HttpServerErrorException – in case of HTTP status 5xx
- UnknownHttpStatusCodeException – in case of an unknown HTTP status
One Can configure a Spring RestTemplate bean as well
- using the default RestTemplateBuilder
- using a RestTemplateCustomizer
- creating RestTemplateBuilder