The need for the HTTP Client API

Until now, Java developers have been using the HttpURLConnection class to request HTTP resources over the network. However, it has multiple downsides, which led to the development of the HTTP Client API.

Introduced in JDK 1.1, the HttpURLConnection class was never designed to work in an asynchronous way; it works in a blocking mode only. This contrasts with the changing nature of the applications and the data that we work with today. The world is moving toward responsive programming, which deals with processing real-time data, and we can't afford to work with blocking communications or one request or response over a connection.

The HttpURLConnection class is also difficult to use for the developers; part of its behavior is not documented. The base class of HttpURLConnection, that is, the URLConnection API, supports multiple protocols, most of which are not used now (for example, Gopher). This API doesn't support HTTP/2, since it was created way earlier than the formulation of HTTP/2.

Also, similar advanced APIs were available, such as Apache HttpClient, Eclipse Netty and Jetty, and others. It was high time that Oracle updated its own HTTP access API, keeping pace with the development and supporting its developers. One of the main goals of the HTTP Client is to have its memory consumption and performance on par with Apache HttpClient, Netty, and Jetty.

HttpURLConnection can't work in an asynchronous, non-blocking manner, which was one of the main reasons for the creation of the HTTP Client.

Now that you know why you need the HTTP Client API, let's get to work with its usage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.86.18