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

Consider adding a progress listener for Callback #80

Open
joshgontijo opened this issue Oct 12, 2017 · 2 comments
Open

Consider adding a progress listener for Callback #80

joshgontijo opened this issue Oct 12, 2017 · 2 comments

Comments

@joshgontijo
Copy link
Owner

From #26

One thing that would make this library even better is to add a simple progress callback that updates as a request is made. For POST/PUT/PATCH etc it would be great for this to monitor upload progress, and for GET/DELETE etc it would be great for download progress. Thoughts? This is another side note, but it would be nice to include a default callback class that provides stubbed implementations of the callback interface for those who don't wish to provide functionality for some of the methods.

Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post")
  .header("accept", "application/json")
  .field("param1", "value1")
  .field("param2", "value2")
  .asJsonAsync(new Callback<JsonNode>() {

    public void failed(UnirestException e) {
        System.out.println("The request has failed");
    }

    public void completed(HttpResponse<JsonNode> response) {
         int code = response.getCode();
         Map<String, String> headers = response.getHeaders();
         JsonNode body = response.getBody();
         InputStream rawBody = response.getRawBody();
    }

    public void cancelled() {
        System.out.println("The request has been cancelled");
    }

    public void progress(long current, long total) {
        System.out.println("Progress: " + ((float)current / (float)total));
    }

});
@smarg120
Copy link

I saw this feature is being requested for 3 years without response....I switched to jodd http client that has this feature.

@joshgontijo
Copy link
Owner Author

@smarg120, I think the maintainers abandoned the original Unirest. I will have a look on jodd http, never heard of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants