13 Jan 2009

REST Client for Java

The other day I was looking for a decent Java REST client to let me use existing REST services.

I couldn't find anything simple enough so thought I'd build my own. It's pushing YAGNI somewhat (extremely lightweight) but seems to do the job pretty well. If you are looking for a very lightweight REST client head over to Google Code:

It's inspired by Rail's ActiveResource pattern: It simply lets you manipulate/interrogate the REST XML responses through Java interface's:

declare the interface
interface Project {String getId();String getName();}

get the resource via the interface
Project project = connection.get("projects/2782118.xml").as(Project.class);

use the object
assertEquals("Zipwire Rest", project.getProjectName());

Lists and complex data structures are handled in a pretty straight forward fashion. If you are not familiar with the power of Java's Proxy class it may be worth a look.