Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.vertx.core.http.HttpClient.postAbs or requestAbs methods are removed in Vertx 4.X.X. Which methods we should use now and how? #72

Closed
sac10nikam opened this issue Aug 1, 2022 · 8 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sac10nikam
Copy link

sac10nikam commented Aug 1, 2022

Questions

io.vertx.core.http.HttpClient.postAbs or requestAbs methods are removed in Vertx 4.X.X. Which methods we should use now and how?

Version

4.3.2

Context

Migrating Vertx 3.9.7 to 4.3.2

Do you have a reproducer?

Yes

  • Link to github project/gist

Steps to reproduce

NA

Extra

JVM 17 - Amazon Corrento

@sac10nikam sac10nikam added the bug Something isn't working label Aug 1, 2022
@sac10nikam sac10nikam changed the title io.vertx.core.http.HttpClient.postAbs method in Vertx 4.X.X is removed. Which method we should use now? io.vertx.core.http.HttpClient.postAbs or requestAbs methods are removed in Vertx 4.X.X. Which methods we should use now and how? Aug 1, 2022
@sac10nikam
Copy link
Author

@pendula95 Do you know this?

@pendula95
Copy link
Member

There was a lot of cleaning work for HttpClient. Most of the methods were removed for simplicity of API changes-in-http-client

If you want to have a http client for application business I would recommend using WebClient instead of HttpClient. As stated in migration guide:

Vert.x web client

Use the Vert.x web client when your applications are web oriented. For example, REST, encoding and decoding HTTP payloads, interpreting the HTTP status response code, and so on.

Vert.x HTTP client

Use the Vert.x HTTP client when your applications are used as HTTP proxy. For example, as an API gateway. The HTTP client has been updated and improved in Vert.x 4.

It is possible to get same behavior as before so here are examples:
This is equivalent to using HttpClient.postAbs("http://enw5gif6c6lhk.x.pipedream.net/test", .....)

httpClient.request(HttpMethod.POST, 80, "enw5gif6c6lhk.x.pipedream.net", "/test", handler1 -> {
            if (handler1.succeeded()) {
                handler1.result().send(handler2 -> {
                    if (handler2.succeeded()) {
                        System.out.println(handler2.result().statusCode());
                        //System.out.println(handler2.result().body().succeeded());
                    } else {
                        handler2.cause().printStackTrace();
                    }
                });
            } else {
                handler1.cause().printStackTrace();
            }
        });

I would recommend using the Futures API as it is much cleaner:

httpClient.request(HttpMethod.POST, 80, "enw5gif6c6lhk.x.pipedream.net", "/test")
                .compose(HttpClientRequest::send)
                .onFailure(Throwable::printStackTrace)
                .onSuccess(response -> System.out.println(response.statusCode()));

Also here is an example using WebClient which has postAbs:

webClient.postAbs("http://enw5gif6c6lhk.x.pipedream.net/test")
                .send()
                .onFailure(Throwable::printStackTrace)
                .onSuccess(response -> System.out.println(response.statusCode()));

You are not the only one who asked this question so it might be a good idea to make a contribution to migration guide, so if you are up for it please take a shoot, especially if you are going to use this as you will get experience from first hand.

@pendula95 pendula95 added the help wanted Extra attention is needed label Aug 1, 2022
@sac10nikam
Copy link
Author

@pendula95 Thanks your quick reply. I appreciate it.

@sac10nikam
Copy link
Author

sac10nikam commented Aug 3, 2022

@pendula95 How can we migrate
io.vertx.core.http.HttpClient.requestAbs in Vertx 4.3.2?

I could see, io.vertx.core.http.HttpClient.requestAbs overloaded methods has been moved to WebClient API. Not sure if I am pointing out correct.

Can we use requestAbs method from Webclient?
Reference: https://vertx.io/docs/apidocs/io/vertx/ext/web/client/WebClient.html

@vietj
Copy link
Contributor

vietj commented Aug 3, 2022

you can use new RequestOptions().setAbsoluteURI(...) and make you request with

@sac10nikam
Copy link
Author

@vietj Thanks. Let me check. Can you share its example?

@pendula95
Copy link
Member

pendula95 commented Aug 3, 2022

HttpClient httpClient = vertx.createHttpClient();
httpClient.request(new RequestOptions().setAbsoluteURI("https://enpc7phb98di.x.pipedream.net")
    .setTimeout(3000))
  .compose(HttpClientRequest::send)
  .onFailure(Throwable::printStackTrace)
  .onSuccess(response -> System.out.println(response.statusCode()));

@sac10nikam
Copy link
Author

Thanks @pendula95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Development

No branches or pull requests

3 participants