Search in sources :

Example 1 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    HttpClient client = vertx.createHttpClient();
    HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
    req.toFlowable().flatMap(resp -> {
        if (resp.statusCode() != 200) {
            throw new RuntimeException("Wrong status code " + resp.statusCode());
        }
        return Flowable.just(Buffer.buffer()).mergeWith(resp.toFlowable());
    }).reduce(Buffer::appendBuffer).map(buffer -> buffer.toString("UTF-8")).subscribe(data -> System.out.println("Server content " + data));
    // End request
    req.end();
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) Flowable(io.reactivex.Flowable) HttpMethod(io.vertx.core.http.HttpMethod) HttpClient(io.vertx.reactivex.core.http.HttpClient) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) Runner(io.vertx.example.util.Runner) Buffer(io.vertx.reactivex.core.buffer.Buffer) Buffer(io.vertx.reactivex.core.buffer.Buffer) HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClient(io.vertx.reactivex.core.http.HttpClient)

Example 2 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    HttpClient client = vertx.createHttpClient();
    HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
    req.toFlowable().flatMap(resp -> {
        if (resp.statusCode() != 200) {
            throw new RuntimeException("Wrong status code " + resp.statusCode());
        }
        return resp.toFlowable();
    }).subscribe(data -> System.out.println("Server content " + data.toString("UTF-8")));
    // End request
    req.end();
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpMethod(io.vertx.core.http.HttpMethod) HttpClient(io.vertx.reactivex.core.http.HttpClient) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) Runner(io.vertx.example.util.Runner) HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClient(io.vertx.reactivex.core.http.HttpClient)

Example 3 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project knotx by Cognifide.

the class SampleApplicationTest method request.

private static Observable<HttpClientResponse> request(HttpClient client, HttpMethod method, int port, String domain, String uri, Action1<HttpClientRequest> requestBuilder) {
    return Observable.unsafeCreate(subscriber -> {
        HttpClientRequest req = client.request(method, port, domain, uri);
        Observable<HttpClientResponse> resp = req.toObservable();
        resp.subscribe(subscriber);
        requestBuilder.call(req);
        req.end();
    });
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClientResponse(io.vertx.reactivex.core.http.HttpClientResponse)

Example 4 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project knotx by Cognifide.

the class HttpRepositoryConnectorProxyImpl method get.

private Observable<HttpClientResponse> get(HttpClient client, RequestOptions requestOptions, MultiMap headers) {
    return Observable.unsafeCreate(subscriber -> {
        HttpClientRequest req = client.get(requestOptions);
        req.headers().addAll(headers);
        if (headers.get(HttpHeaderNames.HOST.toString()) != null) {
            req.setHost(headers.get(HttpHeaderNames.HOST.toString()));
        }
        Observable<HttpClientResponse> resp = req.toObservable();
        resp.subscribe(subscriber);
        req.end();
    });
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClientResponse(io.vertx.reactivex.core.http.HttpClientResponse)

Example 5 with HttpClientRequest

use of io.vertx.reactivex.core.http.HttpClientRequest in project vertx-examples by vert-x3.

the class Client method start.

@Override
public void start() throws Exception {
    HttpClient client = vertx.createHttpClient();
    HttpClientRequest req = client.request(HttpMethod.GET, 8080, "localhost", "/");
    req.toFlowable().flatMap(HttpClientResponse::toFlowable).map(buffer -> buffer.toJsonObject().mapTo(Data.class)).subscribe(data -> System.out.println("Got response " + data.message));
    // End request
    req.end();
}
Also used : HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpMethod(io.vertx.core.http.HttpMethod) HttpClient(io.vertx.reactivex.core.http.HttpClient) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) Runner(io.vertx.example.util.Runner) HttpClientResponse(io.vertx.reactivex.core.http.HttpClientResponse) HttpClientRequest(io.vertx.reactivex.core.http.HttpClientRequest) HttpClient(io.vertx.reactivex.core.http.HttpClient) HttpClientResponse(io.vertx.reactivex.core.http.HttpClientResponse)

Aggregations

HttpClientRequest (io.vertx.reactivex.core.http.HttpClientRequest)7 HttpClientResponse (io.vertx.reactivex.core.http.HttpClientResponse)5 HttpMethod (io.vertx.core.http.HttpMethod)4 Runner (io.vertx.example.util.Runner)4 AbstractVerticle (io.vertx.reactivex.core.AbstractVerticle)4 HttpClient (io.vertx.reactivex.core.http.HttpClient)4 Flowable (io.reactivex.Flowable)2 JsonObject (io.vertx.core.json.JsonObject)1 Buffer (io.vertx.reactivex.core.buffer.Buffer)1