Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created March 29, 2011 04:17
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrigorik/891804 to your computer and use it in GitHub Desktop.
Save igrigorik/891804 to your computer and use it in GitHub Desktop.
Goliath + http_router.rb
require 'goliath'
require 'http_router'
# https://github.com/joshbuddy/http_router
HttpRouter::Rack.override_rack_builder!
class RackRoutes < Goliath::API
map('/get/:id') do |env|
[200, {'Content-type' => 'text/plain'}, ["My id is #{env['router.params'][:id]}\n"]]
end
end
# [0:17:12] igrigorik:~ > curl localhost:3000/get/12
# My id is 12
@mrflip
Copy link

mrflip commented May 21, 2011

how about

  map(':id', :methods => [:get]){|env| ... }
  map(':id', :methods => [:post, :put]){|env| ... }
  map(':id'){|env| ... }  # will catch all remaining

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment