Skip to content
This repository

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 config
Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 script
Octocat-spinner-32 spec
Octocat-spinner-32 tasks
Octocat-spinner-32 website
Octocat-spinner-32 .gitignore
Octocat-spinner-32 History.txt
Octocat-spinner-32 License.txt
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 PostInstall.txt
Octocat-spinner-32 README.txt
Octocat-spinner-32 Rakefile
Octocat-spinner-32 httparty.gemspec
Octocat-spinner-32 setup.rb
= httparty


Makes http fun again!


* Easy get, post, put, delete requests
* Basic http authentication
* Default request query string parameters (ie: for api keys that are needed on each request)
* Automatic parsing of JSON and XML into ruby hashes based on response content-type


The following is a simple example of wrapping Twitter's API for posting updates.

	class Twitter
	  include HTTParty
	  base_uri ''
	  basic_auth 'username', 'password'
	end'/statuses/update.json', :query => {:status => "It's an HTTParty and everyone is invited!"})

That is really it! The object returned is a ruby hash that is decoded from Twitter's json response. JSON parsing is used because of the .json extension in the path of the request. You can also explicitly set a format (see the examples). 

That works and all but what if you don't want to embed your username and password in the class? Below is an example to fix that:

	class Twitter
	  include HTTParty
	  base_uri ''

	  def initialize(u, p)
	    @auth = {:username => u, :password => p}

	  def post(text)
	    options = { :query => {:status => text}, :basic_auth => @auth }'/statuses/update.json', options)
	end'username', 'password').post("It's an HTTParty and everyone is invited!")


Each of the HTTP method (get, post, put and delete) each take a hash of options.
The following keys can be specified in the options:

headers::       A <tt>Hash</tt> of header key/value pairs
query::         A <tt>Hash</tt> of query key/value pairs
body::          The body of the request. If it's a <tt>Hash</tt>, it is
                converted into query-string format, otherwise it is sent
basic_auth::    A <tt>Hash</tt> containing keys for <tt>:username</tt> and
no_follow::     Turns off automatic redirect following


* Active Support >= 2.1


* sudo gem install httparty
Something went wrong with that request. Please try again.