Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Nap is a really simple REST library.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 support
Octocat-spinner-32 test
Octocat-spinner-32 .autotest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .kick
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 NOTES
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 nap.gemspec
README.md

Nap

Nap is an extremely simple REST client for Ruby. It was built to quickly fire off HTTP requests without having to research net/http internals.

Example

gem 'nap'
require 'rest'
require 'json'

response = REST.get('http://twitter.com/statuses/friends_timeline.json', {},
  {:username => '_evan', :password => 'buttonscat'}
)
if response.ok?
  timeline = JSON.parse(response.body)
  puts(timeline.map do |item|
    "#{item['user']['name']}\n\n#{item['text']}"
  end.join("\n\n--\n\n"))
elsif response.forbidden?
  puts "Are you sure you're `_evan' and your password is the name of your cat?"
else
  puts "Something went wrong (#{response.status_code})"
  puts response.body
end

Advanced request configuration

If you need more control over the Net::HTTP request you can pass a block to all of the request methods.

response = REST.get('http://google.com') do |http_request|
  http_request.open_timeout = 15
  http_request.set_debug_output(STDERR)
end

Proxy support

To enable the proxy settings in Nap, you can either use the HTTP_PROXY or http_proxy enviroment variable.

$ env HTTP_PROXY=http://rob:secret@192.167.1.254:665 ruby app.rb

Contributions

Nap couldn't be the shining beacon in the eternal darkness without help from:

  • Eloy Durán
  • Joshua Sierles
  • Thijs van der Vossen
Something went wrong with that request. Please try again.