Summary

Incubated in Java 9, the HTTP Client was standardized in Java 11. This chapter started with an introduction to the HTTP Client API, including the factors that led to its creation. Today's web applications and services should be responsive, supporting asynchronous, non-blocking data transfers. The HTTP Client uses Reactive Streams to achieve these goals.

The HTTP Client can be used to access HTTP resources across the network, using either HTTP/1.1 or HTTP/2, in both synchronous and non-synchronous manners. The HTTP Client API consists of three main classes or interfaces: the HttpClient class,  the HttpRequest class, and the HttpResponse interface. The HttpClient class is used to send a request and retrieve the corresponding responses; HttpRequest encapsulates the details of the requested resource, including the request URI. The HttpResponse class encapsulates the response from the server.

Under the hood, the HTTP Client uses BodySubscriber and BodyPublishers to send and receive the response to and from the server asynchronously, in a non-blocking manner. The BodyPublisher interface extends the Flow.Publisher interface. The BodySubcriber interface extends the Flow.Subscriber interface. 

The chapter included multiple examples to demonstrate common use cases.

A lot of interesting language additions and modifications are in progress as a part of Project Amber at the Oracle Corporation. We'll get started with exploring that in the next chapter.

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

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