Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's Java core's official way to create an HTTP connection in 2016?

I'm looking at HttpURLConnection, existing since JDK 1.1, 1997 (almost 20 years now), and I'm quite astonished that it's still Java core's official way to create HTTP connections.

Since it was published, many libraries tried to simplify(/upgrade) the usage of an HTTP connections, like Apache's HttpClient.

Other libraries tried to simplify REST HTTP calls, like Jersey.

As far as I could found, no wrapper of HttpURLConnection was added to the JDK.

Is HttpURLConnection still Java core's official way to create an HTTP connection?

If not, what's the official way?

like image 314
AlikElzin-kilaka Avatar asked May 19 '16 07:05

AlikElzin-kilaka


1 Answers

The old HttpURLConnection is currently the standard way to perform HTTP requests in Java SE.

Java EE 7 brought the JAX-RS Client API, which is the standard way to consume REST web services built on top of the HTTP protocol.

And Java SE 9, to be released in 2017, will bring a new HTTP client API that implements HTTP/2 and WebSocket, and can replace the legacy HttpURLConnection API. The motivation for a new API is described in the JEP 110:

The existing HttpURLConnection API and its implementation have numerous problems:

  • The base URLConnection API was designed with multiple protocols in mind, nearly all of which are now defunct (ftp, gopher, etc.).
  • The API predates HTTP/1.1 and is too abstract.
  • It is hard to use, with many undocumented behaviors.
  • It works in blocking mode only (i.e., one thread per request/response).
  • It is very hard to maintain.
like image 176
cassiomolin Avatar answered Nov 14 '22 06:11

cassiomolin