

The HTTP method PATCH is not supported.Įspecially for applications in production, it is advisable to replace the standard HttpURLConnection with a proven HTTP client API like Apache when using RestTemplate.Regarding credentials or connection pooling, other HTTP client APIs offer more configuration options and a wider range of functions.This often forces us to work with try/catch to handle the exceptions accordingly. With errors such as 400 Bad Request or 404 Not Found an exception is thrown directly.Especially for productive applications there are good reasons to exchange the HttpURLConnection as underlying HTTP client API because it has some disadvantages, which also affect the use of RestTemplate: Some probably wonder why you should swap the underlying HTTP client API. The Spring Framework offers us the possibility to switch from the standard HTTP client ( HttpURLConnection) to another HTTP client. In addition to Apache HttpComponents, other HTTP clients such as OkHttp or Netty can also be used in the RestTemplate substructure. The HTTP client, on the other hand, takes care of all low-level details of communication via HTTP.

RestTemplate is superior to the HTTP client and takes care of the transformation from JSON or XML to Java objects.

RestTemplate and Apaches HTTP client API work at different levels of abstraction. In today’s blog post we will take a look at how we can use Apache HttpComponents as the HTTP client API for the RestTemplate. In another blog post, we already looked at how we use the class RestTemplate to consume REST web services.
