Search in sources :

Example 1 with CreatePojoRequest

use of io.servicetalk.examples.http.serialization.json.CreatePojoRequest 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 CreatePojoRequest

use of io.servicetalk.examples.http.serialization.json.CreatePojoRequest 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 CreatePojoRequest

use of io.servicetalk.examples.http.serialization.json.CreatePojoRequest 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 CreatePojoRequest

use of io.servicetalk.examples.http.serialization.json.CreatePojoRequest 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)

Example 5 with CreatePojoRequest

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

the class BlockingPojoStreamingClient method main.

public static void main(String[] args) throws Exception {
    try (BlockingStreamingHttpClient client = HttpClients.forSingleAddress("localhost", 8080).buildBlockingStreaming()) {
        BlockingStreamingHttpResponse response = client.request(client.post("/pojos").payloadBody(asList(new CreatePojoRequest("value1"), new CreatePojoRequest("value2"), new CreatePojoRequest("value3")), REQ_STREAMING_SERIALIZER));
        System.out.println(response.toString((name, value) -> value));
        // the full response payload body is drained in case of exceptions
        try (BlockingIterator<PojoResponse> payload = response.payloadBody(RESP_STREAMING_SERIALIZER).iterator()) {
            while (payload.hasNext()) {
                System.out.println(payload.next());
            }
        }
    }
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) RESP_STREAMING_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_STREAMING_SERIALIZER) REQ_STREAMING_SERIALIZER(io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_STREAMING_SERIALIZER) PojoResponse(io.servicetalk.examples.http.serialization.json.PojoResponse) Arrays.asList(java.util.Arrays.asList) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) BlockingIterator(io.servicetalk.concurrent.BlockingIterator) HttpClients(io.servicetalk.http.netty.HttpClients) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) CreatePojoRequest(io.servicetalk.examples.http.serialization.json.CreatePojoRequest) PojoResponse(io.servicetalk.examples.http.serialization.json.PojoResponse) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse)

Aggregations

CreatePojoRequest (io.servicetalk.examples.http.serialization.json.CreatePojoRequest)7 HttpClients (io.servicetalk.http.netty.HttpClients)6 REQ_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_SERIALIZER)4 RESP_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_SERIALIZER)4 PojoResponse (io.servicetalk.examples.http.serialization.json.PojoResponse)3 REQ_STREAMING_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.REQ_STREAMING_SERIALIZER)3 RESP_STREAMING_SERIALIZER (io.servicetalk.examples.http.serialization.json.SerializerUtils.RESP_STREAMING_SERIALIZER)3 BlockingIterator (io.servicetalk.concurrent.BlockingIterator)2 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)2 BlockingStreamingHttpClient (io.servicetalk.http.api.BlockingStreamingHttpClient)2 BlockingStreamingHttpResponse (io.servicetalk.http.api.BlockingStreamingHttpResponse)2 HttpClient (io.servicetalk.http.api.HttpClient)2 HttpResponse (io.servicetalk.http.api.HttpResponse)2 Arrays.asList (java.util.Arrays.asList)2 BlockingIterable (io.servicetalk.concurrent.BlockingIterable)1 ALLOW (io.servicetalk.http.api.HttpHeaderNames.ALLOW)1 HttpPayloadWriter (io.servicetalk.http.api.HttpPayloadWriter)1 POST (io.servicetalk.http.api.HttpRequestMethod.POST)1 CREATED (io.servicetalk.http.api.HttpResponseStatus.CREATED)1 METHOD_NOT_ALLOWED (io.servicetalk.http.api.HttpResponseStatus.METHOD_NOT_ALLOWED)1