HTTP Client Deep Dive

Categories: HTTP Client Java HTTP HTTP/2

JDK 11 saw the advent of a new HTTP Client and important new API for calling content on remote RESTful endpoints. This presentation will just focus on the HTTP Client are how to maximize its use.

We will cover

  • How to setup standard calls

  • How to work with proxies

  • How attach Flow API with either RXJava or Reactor to manipulate the results

  • How to process CompletableStages asynchronously

  • Processing HTTP/2

By the end of the presentation, you will have a complete understanding of the following code

HttpClient client = HttpClient.newHttpClient();

HttpRequest request =
  HttpRequest
    .newBuilder()
    .uri(URI.create(urlString))
    .build();

CompletableFuture<HttpResponse<String>> future =
  client.sendAsync(request,
    HttpResponse.BodyHandlers.ofString());

CompletableFuture<String> stringCompletableFuture = future
  .thenApply(HttpResponse::body)
  .thenApply(JSONDeserializer::processJson)
  .thenApplyAsync(m -> CountryFunctions.findLanguagesByRegion(m, "en", "Americas"));

stringCompletableFuture
  .orTimeout(15, TimeUnit.SECONDS)
  .thenAccept(System.out::println);