Using the HTTP 2 Client API
The HTTP Client API was introduced with Java 9 as an incubating API in the jdk.incubator.http
package. In Java 11, it was standardized and moved to the java.net.http
package. It is a far richer and easier-to-use alternative to the URLConnection
API. In addition to all the basic connection-related functionality, it provides non-blocking (asynchronous) requests and responses using CompletableFuture
and supports both HTTP 1.1 and HTTP 2.
HTTP 2 added the following new capabilities to the HTTP protocol:
- The ability to send data in a binary format rather than textual format; the binary format is more efficient for parsing, more compact, and less susceptible to various errors.
- It is fully multiplexed, thus allowing multiple requests and responses to be sent concurrently using just one connection.
- It uses header compression, thus reducing the overhead.
- It allows a server to push a response to the client’s cache if the client indicates...