As a relative newbie in the Java world, I am finding many things frustratingly obtuse to accomplish that are relatively trivial in many other frameworks. A primary example i
there are libraries and frameworks written on top of NIO/Netty - RxNetty and Vertx which can be helpful to write asynchronous HTTP client
Below is an example code using vertx
public class Client extends AbstractVerticle {
@Override
public void start() throws Exception {
//lambda callback would be called when the response comes back
vertx.createHttpClient().getNow(8080, "localhost", "/", resp -> {
System.out.println("Got response " + resp.statusCode());
resp.bodyHandler(body -> {
System.out.println("Got data " + body.toString("ISO-8859-1"));
});
});
//this code statement will execute before response comes back
System.out.println("I am not blocked");
}
}
you can find the full blown example code from here