The Changelog

Open Source moves fast. Keep up.

Weary, Ruby DSL for HTTP goes 1.0, now built on Rack

Mark Wunsch, whose awesome Tumblr library you might already use, has spent the last few weeks refactoring his Weary project to be fully Rack compatible.

Weary has always sported a rather elegant DSL for wrapping Net::HTTP, but after the big rewrite, you can now use Rack middleware and your client is a Rack application:

# http://developer.github.com/v3/repos/
class GithubRepo < Weary::Client
  domain "https://api.github.com"

  use Rack::Lint

  get :list_user_repos, "/users/{user}/repos" do |resource|
    resource.optional :type
  end

  get :get, "/repos/{user}/{repo}"
end

client = GithubRepo.new
client.list_user_repos(:user => "mwunsch").perform do |response|
  puts response.body if response.success?
end

Check out Mark’s Gilt API wrapper for a complete example of building a wrapper with Weary or the project wiki for more info on how a Weary Request works. Mark has also recorded an introductory screencast that covers what’s new in 1.0:


Have comments? Send a tweet to @TheChangelog on Twitter.

Subscribe to The Changelog Weekly – our weekly email covering everything that hits our open source radar.