tags:

views:

485

answers:

7

Net::HTTP can be rather cumbersome for the standard use case!

A: 

This is what I use: http://rubyforge.org/projects/restful-rails/.

+2  A: 

rest-open-uri is the one that is used heavily throughout the RESTful Web Services book.

gem install rest-open-uri

Example usage:

response = open('https://wherever/foo',
                :method => :put,
                :http_basic_authentication => ['my-user', 'my-passwd'],
                :body => 'payload')

puts response.read
Aaron Hinni
+8  A: 

If you only have to deal with REST, the RESTClient library is fantastic.

If the APIs you're using aren't completely RESTful - or even if they are - HTTParty is really worth checking out. It simplifies using REST APIs, as well as non-RESTful web APIs. Check out this code (copied from the above link):

require 'rubygems'
require 'httparty'

class Representative
  include HTTParty
  format :xml

  def self.find_by_zip(zip)
    get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => zip})
  end
end

puts Representative.find_by_zip(46544).inspect
# {"result"=>{"n"=>"1", "rep"=>{"name"=>"Joe Donnelly", "district"=>"2", "office"=>"1218 Longworth", "phone"=>"(202) 225-3915", "link"=>"http://donnelly.house.gov/", "state"=>"IN"}}}
Clinton R. Nixon
My only issue with HTTParty is th it returns a hash instead of parsing the XML and returning an array of 'Representaive' objects with attribute accessors. Instead of returning the Hash from find_by_zip, i built an array of Representative objects myself and returned that.
Kyle Boon
A: 

HyperactiveResource is in its infancy, but it's looking pretty good.

Bill Turner
A: 

I'm a big fan of rest-client, which does just enough to be useful without getting in the way of your implementation. It handles exceptions intelligently, and supports logging and auth, out of the box.

tomtaylor
A: 

Take a look at asplake's (i.e. my) described_routes and path-to projects/gems on github (which I can't seem to link to from here. Path-to uses HTTParty, but rather than hard-coded URLs like some of the other answers to this question, it uses metadata provided by described_routes. There are several articles describing these gems at positiveincline.com, of which the most relevant to your question is Nested path-to/described_routes and HTTParty.

asplake
A: 

Well, there's always ActiveResource, provided you're on Rails :)

asymmetric