Kong / unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
http://kong.github.io/unirest-java/
MIT License
2.61k stars 594 forks source link

Add map() functionality #261

Closed Risto-Stevcev closed 5 years ago

Risto-Stevcev commented 5 years ago

Is your feature request related to a problem? Please describe. I want to be able to convert HttpResponse<A> to HttpResponse<B> without having to take out the body with getBody. This is because I want the caller to be able to handle the HttpResponse object, I don't just want to return A or B. Specifically it would be nice to able to convert HttpResponse<A[]> to HttpResponse<Stream<A>>.

Describe the solution you'd like A function of type:

HttpResponse<V> map(Function<T, V> func);

That returns a new HttpResponse with all the same data except that it transforms the body with the given function (functor). It would be a new object reference but has all of the same data (headers, parsing errors, etc).

ryber commented 5 years ago

This one is complete and will be in the next release (soon....first lets talk about #262 )