Created
June 14, 2011 20:44
-
-
Save phiggins/1025832 to your computer and use it in GitHub Desktop.
Ugly pure-ruby rack app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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