Sharing Top Content from the Angular-sphere.

Introduction to the JDK HTTP Client

Introduction to the JDK HTTP Client

#Java 

 …

  • It supports HTTP/1.1 and HTTP/2, both synchronous and asynchronous programming models, handles request and response bodies as reactive-streams, and follows the familiar builder pattern.
  • The request and response bodies are exposed as reactive streams ( asynchronous streams of data with non-blocking back pressure.)
  • The and types provide a number of convenience factory methods for creating request publishers and response subscribers for handling common body types such as files, Strings, and bytes.
  • Here’s a summary of the major improvements that HTTP/2 brings: – – Since HTTP/2 is the default preferred protocol, and the implementation seamlessly fallbacks to HTTP/1.1 where necessary, then the JDK HTTP Client is well positioned for the future, when HTTP/2 is more widely deployed.
  • Additional convenience request body publishers and response body subscribers have been added.

The JDK HTTP Client was added in JDK 9. It can be used to
request HTTP resources over the network. It supports
HTTP/1.1 and HTTP/2, both synchronous and
asynchronous programming models, handles request and response
bodies as reactive-streams, and follows the
familiar builder pattern.

The JDK HTTP Client was added in JDK 9. It can be used to request HTTP resources over the network. It supports HTTP/1.1 and HTTP/2, both synchronous and asynchronous programming models, handles request and response bodies as reactive-streams, and follows the familiar builder pattern.

The API currently has an Incubating status, which is reflected in its module and package name. The intent is to incubate the API and then move it towards standardization in a future version of Java SE. More information on incubation can be found in JEP 11, but for now it’s sufficient to recognise the package name, and know how to get access to the API by specifying its containing module, jdk.incubator.httpclient, to the –add-modules command line option. The Maven compiler and surefire plugins can be configured as follows:

To send a request, first create an from its builder. The builder can be used to configure per-client state, like:

Once built, an can be used to send multiple requests.

An is created from its builder. The request builder can be used to set:

Once built an is immutable, and can be sent multiple times.

Requests can be sent either synchronously or asynchronously. The synchronous API, as expected, blocks until the is available.

The asynchronous API returns immediately with a that completes with…

Introduction to the JDK HTTP Client

Comments are closed, but trackbacks and pingbacks are open.