Skip to content

Jersey vs. HttpURLConnection for a RESTful Android client

Since Google officially deprecated the HTTPClient and related methods after Android API 22. I thought it would be interesting to compare their recommended alternative (HttpURLConnection) with my preferred RESTful client; Jersey.

The following example is an implementation of HttpURLConnection to query a RESTful Webservice to return a String.

The following is a small class implementation of the Jersey client framework, I decided to include the whole class for context.

Here is how you would query for a String result within an Android AsyncTask:

The biggest difference is the verbosity of HttpURLConnection. Here are a few other more obscure differences:

1. HttpURLConnection has a poorly designed API. It is very verbose, with a large library of methods and boilerplate required to achieve even the smallest transactional logic.

2. HttpURLConnection is very well documented. It is easy to find examples of whatever logic you are trying to implement.

3. Comparative performance is negligible. Especially when Jersey uses HttpUrlConnection as a fall-back API.

4. The Jersey client is Android-specific. It has been optimised specifically for RESTful requests. Whereas HttpUrlConnection is a general purpose, standalone API that can be used in any Java environment.

5. Jersey is merely a wrapper API. It has a number of fall-backs (HttpUrlConnection being one of them). Its biggest strength is its API design, for extremely light-weight implementation requirements.

Published inAndroidJavaMobileProgramming

One Comment

  1. Indeed very useful, I was looking for comlaration between Jersey Client’s heavy implemantation as defined on the docs to HttpUrlConnection, which requires longer to write but I know it from beforehands. Indeed as you described it helped me to know the both rely on httpconnection, however I’m still looking towards to lay wether Jersey Client is indeed too heavy to use on the server side or not.

Leave a Reply

Your email address will not be published. Required fields are marked *