Skip to content

Instantly share code, notes, and snippets.

@phiggins
Created June 14, 2011 20:44
Show Gist options
  • Select an option

  • Save phiggins/1025832 to your computer and use it in GitHub Desktop.

Select an option

Save phiggins/1025832 to your computer and use it in GitHub Desktop.
Ugly pure-ruby rack app
class MyRackApp
def call(env)
case env.values_at('REQUEST_METHOD', 'PATH_INFO')
when ['GET', '/']
[200, {}, "This is the root"]
when ['GET', '/greet']
name = env['QUERY_STRING'][/name=([^&]*)/, 1] || "World"
[200, {}, "Hello, #{name}"]
when ['POST', '/greet']
name = env["rack.input"].read[/name=([^&]*)/, 1] || "World"
[200, {}, "Nice to meet you, #{name}."]
else
[404, {}, '']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment