Review of new Http client API

Chris Hegarty chris.hegarty at oracle.com
Thu Aug 23 08:40:50 PDT 2012



On 23/08/2012 16:34, Paul Sandoz wrote:
> ...
>
> OK, i would be inclined to separate out the instance used for building from the instance passed around, so one cannot muck around with the state of the latter.

Agreed, HttpResponse could use a builder pattern.

>> Then user code may do:
>>
>>   AsyncHttpRequest request.async()
>>                .onHeaders(r ->  dumpHeaders(r))
>>                .onError((r,t) ->  handleError(r,t));
>>                .onBodyPart((r,bb,c) ->  transformBody(r,bb,t));
>>   client.sendRequest(request);
>>
>
> If these calls are on* calls are optional and one is not interested in when the headers have been received one could omit the onHeaders call, infact all those methods could be optional. That certainly simplifies things.

Right.

>>   ....
>>
>>   void dumpHeaders(HttpResponse r) {
>>       System.out.println(r);
>>   }
>>   void handleError(HttpResponse r, t) {
>>       throw t;
>>   }
>>   void transformBody(HttpResponse r, bb, boolean complete) {
>>       System.out.println("Hello there!");
>>   }
>>
>
> FWIW you could use method references:
>
>     AsyncHttpRequest request.async()
>                .onHeaders(whateverthatclassiscalled::dumpHeaders)

Ok, great.

-Chris.

>                ...
>
> Paul.
>
>
>> Some experimentation is necessary to find a good balance here.
>>
>> -Chris.



More information about the net-dev mailing list