June 2018
Intermediate to advanced
280 pages
7h 46m
English
Java 9 brings a new sleek HTTP client API with HTTP/2 support. Let's take a closer look by running an example in jshell.
To use httpclient, we need to start jshell with the jdk.incubator.httpclient module. The following command tells jshell to add the required module:
jshell -v --add-modules jdk.incubator.httpclient
Now lets import the API:
jshell> import jdk.incubator.http.*;
Create an HttpClient object using the following code:
jshell> HttpClient httpClient = HttpClient.newHttpClient();httpClient ==> jdk.incubator.http.HttpClientImpl@6385cb26| created variable httpClient : HttpClient
Let's create a request object for a URL https://www.packtpub.com/:
jshell> HttpRequest httpRequest = HttpRequest.newBuilder().uri(new URI("https://www.packtpub.com/")).GET().build(); ...Read now
Unlock full access