Net::HTTP can be rather cumbersome for the standard use case!
views:
485answers:
7rest-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
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"}}}
HyperactiveResource is in its infancy, but it's looking pretty good.
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.
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.