Search in sources :

Example 1 with HttpResponse

use of io.vertx.mutiny.ext.web.client.HttpResponse in project reactive-systems-in-java by cescoffier.

the class UniApi method main.

public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    WebClient client = WebClient.create(vertx);
    Uni<HttpResponse<Buffer>> uni = client.getAbs("https://httpbin.org/json").send();
    uni.onItem().transform(HttpResponse::bodyAsJsonObject).onFailure().recoverWithItem(new JsonObject().put("message", "fallback")).subscribe().with(json -> System.out.println("Got json document: " + json));
}
Also used : HttpResponse(io.vertx.mutiny.ext.web.client.HttpResponse) JsonObject(io.vertx.core.json.JsonObject) Vertx(io.vertx.mutiny.core.Vertx) WebClient(io.vertx.mutiny.ext.web.client.WebClient)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 Vertx (io.vertx.mutiny.core.Vertx)1 HttpResponse (io.vertx.mutiny.ext.web.client.HttpResponse)1 WebClient (io.vertx.mutiny.ext.web.client.WebClient)1