In this recipe, we will look at how to make an asynchronous GET request. In an asynchronous request, we don't wait for the response; instead, we handle the response whenever it is received by the client. In jQuery, we will make an asynchronous request and provide a callback that takes care of processing the response, while in the case of Java, we get an instance of java.util.concurrent.CompletableFuture, and then we invoke the thenApply method to process the response. Let's see this in action.
Making an asynchronous HTTP request
How to do it...
- Create an instance of HttpClient using its builder, HttpClient.Builder:
HttpClient client = HttpClient.newBuilder().build();
- Create an instance of HttpRequest using...