Skip to content
This repository

An HTTP library for Ruby that takes advantage of everything HTTP has to offer.

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib implemented a promiscuous basic authenticator May 26, 2011
Octocat-spinner-32 spec implemented a promiscuous basic authenticator May 26, 2011
Octocat-spinner-32 .autotest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile Modernize, clean up some bitrot March 24, 2011
Octocat-spinner-32 History.txt
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 Manifest
Octocat-spinner-32 README.markdown Update readme with new convenience methods January 26, 2010
Octocat-spinner-32 Rakefile Modernize, clean up some bitrot March 24, 2011
Octocat-spinner-32 resourceful.gemspec Update gemspec June 07, 2010
README.markdown

Resourceful

Resourceful provides a convenient Ruby API for making HTTP requests.

Features:

  • GET, PUT, POST and DELETE HTTP requests
  • HTTP Basic and Digest authentication
  • HTTP Caching with pluggable backends
  • Follow redirects based on the results of a callback

More Info

Examples

Getting started

gem install resourceful

Simplest example

require 'resourceful'
resp = Resourceful.get('http://rubyforge.org')
puts resp.body

Get a page requiring HTTP Authentication

my_realm_authenticator = Resourceful::BasicAuthenticator.new('My Realm', 'admin', 'secret')
http = Resourceful::HttpAccessor.new(:authenticator => my_realm_authenticator)
resp = http.resource('http://example.com/').get
puts resp.body

Redirection based on callback results

Resourceful will by default follow redirects on read requests (GET and HEAD), but not for POST, etc. If you want to follow a redirect after a post, you will need to set the resource#on_redirect callback. If the callback evaluates to true, it will follow the redirect.

resource = http.resource('http://example.com/redirect_me')
resource.on_redirect { |req, resp| resp.header['Location'] =~ /example.com/ }
resource.get  # Will only follow the redirect if the new location is example.com

Post a URL encoded form

 require 'resourceful'
 http = Resourceful::HttpAccessor.new
 resp = http.resource('http://mysite.example/service').
          post(Resourceful::UrlencodedFormData.new(:hostname => 'test', :level => 'super'))

Post a Mulitpart form with a file

 require 'resourceful'
 http = Resourceful::HttpAccessor.new
 form_data = Resourceful::MultipartFormData.new(:username => 'me')
 form_data.add_file('avatar', '/tmp/my_avatar.png', 'image/png')
 resp = http.resource('http://mysite.example/service').post(form_data)

Put an XML document

 require 'resourceful'
 http = Resourceful::HttpAccessor.new
 resp = http.resource('http://mysite.example/service').
          put('<?xml version="1.0"?><test/>', :content_type => 'application/xml')

Delete a resource

 require 'resourceful'
 http = Resourceful::HttpAccessor.new
 resp = http.resource('http://mysite.example/service').delete

Copyright

Copyright (c) 2008 Absolute Performance, Inc, Peter Williams. Released under the MIT License.

Something went wrong with that request. Please try again.