Jochen has posted 2 posts at DZone. View Full User Profile

Resty for Java - a simple, light-weight HTTP/REST client API

01.03.2011
| 5596 views |
  • submit to reddit
Location: 
San Francisco

Tired of using tons of code around URLConnection?  Apache HTTP client too complex? Jersey client too fickle?

Maybe Resty is to your liking then.

Resty is a small, convenient API to talk to RESTful services from Java.

Its focus is on simplicity and ease-of-use, often requiring only two lines of code to access RESTful web services.

Basic usage is very simple:
Create a Resty instance, then call one of the content type specific methods to GET  the contents of an UR (or POST to it and stuff).

Here is an example on how to use the geonames web service. It retrieves the JSON object and gets the name of a place from the zip code using an JasonPath or XPath-like expression:

Resty r = new Resty();
String name = r.json("http://ws.geonames.org/postalCodeLookupJSON?postalcode=66780&country=DE").
get("postalcodes[0].placeName").toString();

 More on http://beders.github.com/Resty/

 Hosted over at github. Come over and help out. It's fun!

0
Published at DZone with permission of its author, Jochen Bedersdorfer.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)