HTTP Easy | Cubano

HttpEasy provides a fluent style wrapper around HttpURLConnection. It can:

  • handle most HTTP methods (GET, POST, HEAD, etc)
  • upload and download files
  • perform REST and SOAP requests
  • handle corporate proxies, including NTLM proxies which is something that I’ve seen several popular libraries struggle with

HttpEasy has full support for HTTP methods such as GET, POST, HEAD, etc and supports the REST and SOAP protocols and parsing JSON and XML responses.

This is been designed with a fluent REST API similar to RestEasy and RestAssurred with the only real difference being that it has great proxy support.

There are two starting points for creating a rest request:

  • HttpEasy.withDefaults() - allows you to set some settings that apply to all requests such as configuring a proxy
  • HttpEasy.request() - performs the actual call, these HTTP methods are implemented: GET, HEAD, POST, PUT, DELETE

Note: if your url can contain weird characters you will want to encode it, something like this: myUrl = URLEncoder.encode(myUrl, “UTF-8”);


HttpEasyReader r = HttpEasy.request()
    .path(viewPath + "?startkey=\"{startkey}\"&endkey=\"{endkey}\"")
    .urlParameters(startKey[0], endKey[0])

String id = r.jsonPath("rows[0].doc._id").getAsString();
String rev = r.jsonPath("rows[0].doc._rev").getAsString();

Error Handling

An IOException is thrown whenever a call returns a response code that is not part of the SUCCESS family (ie 200-299).

In order to prevent an exception being thrown for an expected response use one of the following methods:

  • request().doNotFailOn(Integer… reponseCodes)
  • request().doNotFailOn(Family… responseFamily)


Supports two formats

  • http://username:password@where.ever
  • request().authorization(username, password)

Host and Certificate Verification

There is no fine grained control, its more of an all or nothing approach:

// Global

//Per Request


Only basic authentication is supported, although I believe the domain can be added by included “domain/” in front of the username (not tested)

    .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(user, password))))
    .proxyAuth(userName, password)

For automatic proxy detection you can use the following, however this will not automatically supply a username and password if the proxy requires authentication for the request being made.



Redirects are NOT automatically followed - at least for REST base calls - even though the documentation for HttpURLConnection says that it should…

HttpEasyReader response = HttpEasy.request()

if (response.getResponseCodeFamily() == Family.REDIRECTION) {
    url = response.getHeaderField("Location");


Logging of requests and responses can be enabled by calling logRequestDetails() or, if using Eclipse, the TCP/IP Monitor utility.