Chapter 5. Fluent API

5.1. Easy to use facade API

As of version of 4.2 HttpClient comes with an easy to use facade API based on the concept
of a fluent interface. Fluent facade API exposes only the most fundamental functions of
HttpClient and is intended for simple use cases that do not require the full flexibility of
HttpClient. For instance, fluent facade API relieves the users from having to deal with
connection management and resource deallocation.

Here are several examples of HTTP requests executed through the HC fluent API

// Execute a POST with a custom header through the proxy containing a request body
// as an HTML form and save the result to the file
Request.Post("http://somehost/some-form")
.addHeader("X-Custom-header", "stuff")
.viaProxy(new HttpHost("myproxy", 8080))
.bodyForm(Form.form().add("username", "vip").add("password", "secret").build())
.execute().saveContent(new File("result.dump"));

One can also use Executor directly in order to execute requests in
a specific security context whereby authentication details are cached and re-used for
subsequent requests.

5.1.1. Response handling

The fluent facade API generally relieves the users from having to deal with
connection management and resource deallocation. In most cases, though, this comes at
a price of having to buffer content of response messages in memory. It is highly
recommended to use ResponseHandler for HTTP response
processing in order to avoid having to buffer content in memory.