Skip to content

Instantly share code, notes, and snippets.

@JoergWMittag
Forked from igrigorik/webapp.rb
Created November 16, 2010 22:36
Show Gist options
  • Save JoergWMittag/702659 to your computer and use it in GitHub Desktop.
Save JoergWMittag/702659 to your computer and use it in GitHub Desktop.
require 'rack'
class Object
def webapp
tap {
def self.call(env)
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
}
end
end
Rack::Handler::WEBrick.run [].webapp, Port: 9292
# ^^^^^^^^^^^
# | (x)
# ROFLSCALE DB ---/
#
# http://localhost:9292/push/1 -> 1
# http://localhost:9292/push/2 -> 12
# http://localhost:9292/push/3 -> 123
# http://localhost:9292/to_a -> 123
# http://localhost:9292/pop -> 3
# http://localhost:9292/shift -> 1
# Implementations in other languages (thanks guys!):
# Node.js: https://gist.github.com/700995
# Groovy: https://gist.github.com/702337
# Python: https://gist.github.com/702001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment