Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

Nestful: A Simple Ruby HTTP/REST Client Library

By Peter Cooper / April 28, 2010

Nestful is a simple HTTP/REST client library for Ruby, developed by Alex MacCaw (of Juggernaut) fame. Nestful allows you to consume basic Web services easily, usually in a single line of code. It can deal with JSON, buffered downloads, and callbacks out of the box.

HTTParty is the current, de-facto simple HTTP/REST client library used by most Rubyists (when net/http won't do or when Typhoeus is too overkill) but Nestful differs enough from HTTParty to live alongside it. While HTTParty encourages you to build up some structure and separate the types of resources you're accessing into classes (that HTTParty then extends), Nestful offers a simpler, "just call a method from anywhere" approach.

Some basic Nestful examples:

Nestful.get 'http://example.com' #=> "body"
Nestful.post 'http://example.com', :format => :form #=> "body"
Nestful.get 'http://example.com', :params => {:nestled => {:params => 1}}
Nestful.get 'http://example.com', :format => :json #=> {:json_hash => 1}
Nestful::Resource.new('http://example.com')['assets'][1].get(:format => :xml) #=> {:xml_hash => 1}

Nestful's features include:

  • Simple API
  • File buffering
  • Before/Progress/After Callbacks
  • JSON & XML requests
  • Multipart requests (file uploading)
  • Resource API
  • Proxy support
  • SSL support

Comments

  1. Technocrat says:

    This is different from REST Client how?

  2. Alex says:

    Technocrat,

    You're right - this is similar to RestClient. However, I guess I made Nestful as an act of stubbornness of my part - I personally didn't like RestClient's code or API - and had a enough issues with it to make my own library.

    Alex

  3. Sohan says:

    Your post has been linked at the drink rails blog.

  4. Tim says:

    Hey, are there some examples of how this is used in an application?

Other Posts to Enjoy

Twitter Mentions