views:

232

answers:

4

So I'm getting started learning Rails. Now that Rails 3 is out, I want to stick to learning the Rails 3 way of doing things. One of the things I want to learn how to do is how to consume web services / work with third party REST APIs / create "mashup" applications. I've only done minimal work like this with PHP and pre-built libraries.

Can someone please lead me to some resources, best practices, or give me a quick 101 lesson on how to start working with these types of APIs? What gems should I use? Some sample code to get me started would be much appreciated.

Update: I am specifically trying to use the Google Books API (non-authenticated). Since there is no client library for this API, I'm wondering how other Ruby/Rails developers are working with APIs that don't come with their own Ruby library. That's why I'm looking for a more generic solution to working with "fill in the blank" API.

Update: After some research, I noticed the Net::HTTP library. All the tutorials that talked about it were fairly old. Is this still the best library to use for consuming RESTful web services? Or is there a newer Gem that makes this easier? I just want to know which gem/library I should use, and how to work with the XML/JSON result that is returned.

Update: This presentation was really helpful. It mentions a bunch of different libraries and shows examples of some of the libraries mentioned below: http://www.slideshare.net/pengwynn/json-and-the-apinauts

A: 

You find a lot of resources on http://github.com. SOAP sucks, as far as I heard. Cool guys use REST. Screw best practices. And I recommend you the DataMapper gem over ActiveRecord. You find a lot of sample code on github too.

Tass
ActiveRecord works pretty well but more importantly it has a huge community behind it. Other than that I agree.
Peter DeWeese
You don't really care about community if the software shows you the birdie.
Tass
Yeah, I'm already using ActiveRecord so I'd rather stick with that to get started. Also, that's not really relevant to the question, since I'm asking about consuming web services and not mapping data. Also, I couldn't find anything helpful on github. Maybe you can post some code samples?
Andrew
http://github.com/search?q=rails+example
Tass
+2  A: 

I'd recommend REST with Nokogiri: http://railscasts.com/episodes/190-screen-scraping-with-nokogiri Nokogiri works well with xml too, not just HTML.

Tim
+3  A: 

I'm a pretty big fan of HTTParty.

It's an abstraction layer on top of Net::HTTP with a nice little DSL for consuming web services. Here's a good example how easy it is to use.

It's not without some warts (lots of dependencies) but it's really the way to go if you're on the consuming side.

mando
+1 for HTTParty. It really does make consuming rest endpoints easy; most recent Ruby wrappers around APIs use it.
Chris Heald
A: 

Weary is a really neat DSL for consuming RESTful services.

Clearly inspired by HTTParty but a bit newer and a bit more concise.

johngrimes