I am using Apache's HttpClient Fluent Facade in Java in some sample code for developers to extend. They really like the fluent facade, with its capability to just call:
this.body = Request.Get(uri.build()).execute().returnContent().asString();
Additionally, I could get the status code by callling:
this.statusCode = Request.Get(uri.build()).execute().returnResponse().getStatusLine().getStatusCode();
Unfortunately, there are several instances where I need the status code in addition to the body. Based on this question, I see that I could have them learn the HttpClient object -
HttpResponse response = client.execute(httpGet);
String body = handler.handleResponse(response);
int code = response.getStatusLine().getStatusCode();
but, that means initializing the HttpClient object and seemingly rejecting the Fluent interface and the Request.Get (or Post) syntax. Is there a way to get both the status code and the body without losing the Fluent syntax and without making two discrete calls?