Search in sources :

Example 11 with WebClient

use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    WebClient client = WebClient.create(vertx);
    client.get(8080, "localhost", "/").send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            System.out.println("Got HTTP response with status " + response.statusCode() + " with data " + response.body().toString("ISO-8859-1"));
        } else {
            ar.cause().printStackTrace();
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) WebClient(io.vertx.ext.web.client.WebClient)

Example 12 with WebClient

use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    WebClient client = WebClient.create(vertx);
    client.get(8080, "localhost", "/").as(BodyCodec.json(User.class)).send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<User> response = ar.result();
            System.out.println("Got HTTP response body");
            User user = response.body();
            System.out.println("FirstName " + user.firstName);
            System.out.println("LastName " + user.lastName);
            System.out.println("Male " + user.male);
        } else {
            ar.cause().printStackTrace();
        }
    });
}
Also used : WebClient(io.vertx.ext.web.client.WebClient)

Example 13 with WebClient

use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    WebClient client = WebClient.create(vertx);
    MultiMap form = MultiMap.caseInsensitiveMultiMap();
    form.add("firstName", "Dale");
    form.add("lastName", "Cooper");
    form.add("male", "true");
    client.post(8080, "localhost", "/").sendForm(form, ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            System.out.println("Got HTTP response with status " + response.statusCode());
        } else {
            ar.cause().printStackTrace();
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MultiMap(io.vertx.core.MultiMap) WebClient(io.vertx.ext.web.client.WebClient)

Example 14 with WebClient

use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    WebClient client = WebClient.create(vertx);
    Buffer body = Buffer.buffer("Hello World");
    client.put(8080, "localhost", "/").sendBuffer(body, ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            System.out.println("Got HTTP response with status " + response.statusCode());
        } else {
            ar.cause().printStackTrace();
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) WebClient(io.vertx.ext.web.client.WebClient)

Example 15 with WebClient

use of io.vertx.ext.web.client.WebClient in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    WebClient client = WebClient.create(vertx);
    JsonObject user = new JsonObject().put("firstName", "Dale").put("lastName", "Cooper").put("male", true);
    client.put(8080, "localhost", "/").sendJson(user, ar -> {
        if (ar.succeeded()) {
            HttpResponse<Buffer> response = ar.result();
            System.out.println("Got HTTP response with status " + response.statusCode());
        } else {
            ar.cause().printStackTrace();
        }
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) JsonObject(io.vertx.core.json.JsonObject) WebClient(io.vertx.ext.web.client.WebClient)

Aggregations

WebClient (io.vertx.ext.web.client.WebClient)16 Buffer (io.vertx.core.buffer.Buffer)11 JsonObject (io.vertx.core.json.JsonObject)3 MultiMap (io.vertx.core.MultiMap)2 Vertx (io.vertx.core.Vertx)2 VertxOptions (io.vertx.core.VertxOptions)2 WebClientOptions (io.vertx.ext.web.client.WebClientOptions)2 Future (io.vertx.core.Future)1 FileProps (io.vertx.core.file.FileProps)1 FileSystem (io.vertx.core.file.FileSystem)1 OpenOptions (io.vertx.core.file.OpenOptions)1 JksOptions (io.vertx.core.net.JksOptions)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 HttpResponse (io.vertx.ext.web.client.HttpResponse)1 BodyCodec (io.vertx.ext.web.codec.BodyCodec)1 Checkpoint (io.vertx.junit5.Checkpoint)1 VertxExtension (io.vertx.junit5.VertxExtension)1 VertxTestContext (io.vertx.junit5.VertxTestContext)1