Skip to content

Instantly share code, notes, and snippets.

@ntulip
Forked from igrigorik/webapp.rb
Created November 16, 2010 16:42
Show Gist options
  • Save ntulip/702047 to your computer and use it in GitHub Desktop.
Save ntulip/702047 to your computer and use it in GitHub Desktop.

Revisions

  1. @igrigorik igrigorik revised this gist Nov 16, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webapp.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ class Object
    def webapp
    class << self
    define_method :call do |env|
    func, *attrs = env['REQUEST_PATH'].split('/').reject(&:empty?)
    func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
    [200, {}, send(func, *attrs)]
    end
    end
  2. @igrigorik igrigorik revised this gist Nov 15, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion webapp.rb
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ class << self

    # http://localhost:9292/push/1 -> 1
    # http://localhost:9292/push/2 -> 12
    # http://localhost:9292/push/2 -> 123
    # http://localhost:9292/push/3 -> 123

    # http://localhost:9292/to_a -> 123

  3. @igrigorik igrigorik created this gist Nov 13, 2010.
    30 changes: 30 additions & 0 deletions webapp.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    require 'rubygems'
    require 'rack'

    class Object
    def webapp
    class << self
    define_method :call do |env|
    func, *attrs = env['REQUEST_PATH'].split('/').reject(&:empty?)
    [200, {}, send(func, *attrs)]
    end
    end
    self
    end
    end

    Rack::Handler::Mongrel.run [].webapp, :Port => 9292
    # ^^^^^^^^^^^
    # | (x)
    # ROFLSCALE DB ---/
    #


    # http://localhost:9292/push/1 -> 1
    # http://localhost:9292/push/2 -> 12
    # http://localhost:9292/push/2 -> 123

    # http://localhost:9292/to_a -> 123

    # http://localhost:9292/pop -> 3
    # http://localhost:9292/shift -> 1