Sunday, July 19, 2009

Patron: a Ruby HTTP client library

I was just trying out Patron, the new ruby client library, by Phillip Toland.

Patron is based on libcurl. and providing nice usable interface, which allows you to make http requests easily and with as much customization as you need. Let us take a quick usage sample here:

irb(main):036:0> require 'rubygems'
=> false
irb(main):037:0> require 'patron'
=> false
irb(main):038:0> sess = Patron::Session.new
=> #<Patron::Session:0xb7a9f878>
irb(main):039:0> sess.base_url = "http://www.google.com"
=> "http://www.google.com"
irb(main):040:0> resp = sess.get("/intl/en/about.html")
=> #<Patron::Response @status_line='HTTP/1.0 200 OK'>
irb(main):041:0> puts resp.body

Checkout the documentation for more samples and usage notes.