How to Consume Project Nimbus Dataservices via REST in Java/Android

2010-12-21

In my previous post, I’ve wrote about consuming Project Nimbus Datasets in Ruby through their REST API interface.

Right now, on Project Nimbus’s guides to consuming their datasets in Java/Android currently introduces two method. One is to use the Restlet framework to connect, and another is through a manual webservice method.

I particulaly found the two tutorials lacking, especially for a beginning Java guy, or a Rusty java guy. The webservice tutorial have lots of holes in between and might throw off new users, like how it threw me off.

So instead, I found another way to consume the dataset, and I thought I’ll share with you how I did it.

Things you’re going to need:

That is all :)

Now all you need to do is to add the following snippet, with your key and uniqueid, and you’re set. I think the codes are pretty self-explainatory.

//Creating a URLConnection.
//Change the following URL to the dataset path that you'd like to access
final String LOGIN_URL = "http://lta.projectnimbus.org/ltaodataservice.svc/TrafficConditionSet";
RestClient client = new RestClient(LOGIN_URL);
client.AddHeader("AccountKey", <Your Nimbus API Key>);
client.AddHeader("UniqueUserID", <A Unique UserID>);
 
try {
    client.Execute(RequestMethod.GET);
    String response = client.getResponse();

    // Do whatever you want with 'response'
    // I'd recommend using SAXParser to iterate through the results

    }
catch(Exception e){
    e.printStackTrace();
}