Http/2 Client API জাভা ৯-এ প্রবর্তিত। এর Http/1.1-এর চেয়ে বেশি পারফরম্যান্স ইমপ্রুভমেন্ট রয়েছে এবং সার্ভার-সাইড পুশ ইভেন্ট সাপোর্ট করে। এটি ওয়েবসাইটকে এফিশিয়েন্ট এবং ফাস্ট ব্রাউজ করার জন্য করে। Http/2 Client একটি ইনকিউবেটর মডিউল নামের jdk.incubator.httpclient, অর্থাৎ সব ফিচার এখনো ফাইনালাইজড নয়, ভবিষ্যতে জাভা ভার্সনে নতুন পরিবর্তন আসতে পারে। এটি jdk.incubator.http প্যাকেজ এক্সপোর্ট করে যাতে সকল পাবলিক API থাকে।
Http/2 Client ব্যবহার
Http/2 Client ব্যবহার করতে হলে ইনকিউবেটর মডিউল ব্যবহার করতে হয়, সিম্পলি httpclient মডিউল JShell-এ "--add-modules" কমান্ড দিয়ে পাস করতে হয়:
C:\>jshell -v --add-modules jdk.incubator.httpclient | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro
উদাহরণ
jshell> import jdk.incubator.http.*;
jshell> HttpClient httpClient = HttpClient.newHttpClient();
httpClient ==> jdk.incubator.http.HttpClientImpl@534df152
| created variable httpClient : HttpClient
jshell> HttpRequest httpRequest = HttpRequest.newBuilder().uri(new URI("https: //www.google.com")).GET().build();
httpRequest ==> https://www.google.com GET
| created variable httpRequest : HttpRequest
jshell> HttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandler.asString());
httpResponse ==> jdk.incubator.http.HttpResponseImpl@609cd4d8
| created variable httpResponse : HttpResponse
jshell> System.out.println(httpResponse.statusCode());
403
jshell> System.out.println(httpResponse.body());
Apache HTTP Server Test Page powered by CentOS Testing 123..
... (HTML কন্টেন্ট)