Search in sources :

Example 1 with RESP_SERIALIZER

use of io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER in project servicetalk by apple.

the class PojoClient method main.

public static void main(String[] args) throws Exception {
    try (HttpClient client = HttpClients.forSingleAddress("localhost", 8080).build()) {
        client.request(client.post("/pojos").payloadBody(new CreatePojoRequest("value"), REQ_SERIALIZER)).whenOnSuccess(resp -> {
            System.out.println(resp.toString((name, value) -> value));
            System.out.println(resp.payloadBody(RESP_SERIALIZER));
        }).toFuture().get();
    }
}
Also used : CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) REQ_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER) HttpClient(io.servicetalk.http.api.HttpClient) RESP_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER) HttpClients(io.servicetalk.http.netty.HttpClients) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) HttpClient(io.servicetalk.http.api.HttpClient)

Example 2 with RESP_SERIALIZER

use of io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER in project servicetalk by apple.

the class BlockingPojoClient method main.

public static void main(String[] args) throws Exception {
    try (BlockingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlocking()) {
        HttpResponse resp = client.request(client.post("/pojos").payloadBody(new CreatePojoRequest("value"), REQ_SERIALIZER));
        System.out.println(resp.toString((name, value) -> value));
        System.out.println(resp.payloadBody(RESP_SERIALIZER));
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) REQ_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER) HttpResponse(io.servicetalk.http.api.HttpResponse) RESP_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) HttpResponse(io.servicetalk.http.api.HttpResponse)

Example 3 with RESP_SERIALIZER

use of io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER in project servicetalk by apple.

the class PojoUrlClient method main.

public static void main(String[] args) throws Exception {
    try (HttpClient client = HttpClients.forMultiAddressUrl().build()) {
        client.request(client.post("http://localhost:8080/pojos").payloadBody(new CreatePojoRequest("value"), REQ_SERIALIZER)).whenOnSuccess(resp -> {
            System.out.println(resp.toString((name, value) -> value));
            System.out.println(resp.payloadBody(RESP_SERIALIZER));
        }).toFuture().get();
    }
}
Also used : CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) REQ_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER) HttpClient(io.servicetalk.http.api.HttpClient) RESP_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER) HttpClients(io.servicetalk.http.netty.HttpClients) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) HttpClient(io.servicetalk.http.api.HttpClient)

Example 4 with RESP_SERIALIZER

use of io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER in project servicetalk by apple.

the class BlockingPojoUrlClient method main.

public static void main(String[] args) throws Exception {
    try (BlockingHttpClient client = HttpClients.forMultiAddressUrl().buildBlocking()) {
        HttpResponse resp = client.request(client.post("http://localhost:8080/pojos").payloadBody(new CreatePojoRequest("value"), REQ_SERIALIZER));
        System.out.println(resp.toString((name, value) -> value));
        System.out.println(resp.payloadBody(RESP_SERIALIZER));
    }
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) REQ_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER) HttpResponse(io.servicetalk.http.api.HttpResponse) RESP_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) HttpResponse(io.servicetalk.http.api.HttpResponse)

Aggregations

CreatePojoRequest (io.servicetalk.examples.http.serialization.json.CreatePojoRequest)4 REQ_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER)4 RESP_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER)4 HttpClients (io.servicetalk.http.netty.HttpClients)4 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)2 HttpClient (io.servicetalk.http.api.HttpClient)2 HttpResponse (io.servicetalk.http.api.HttpResponse)2