Skip to content

Instantly share code, notes, and snippets.

@abdulvayani
Created December 3, 2009 19:16
Show Gist options
  • Save abdulvayani/248442 to your computer and use it in GitHub Desktop.
Save abdulvayani/248442 to your computer and use it in GitHub Desktop.
class Bennet
@routes = {}
def self.get(path, &content)
@routes[path] = content.call
end
def self.call_content(ret, content)
[ret, {"content-type" => "text"}, [content]]
end
def self.call(env)
path = env["PATH_INFO"]
if @routes.include?(path)
call_content(200, @routes[path])
else
call_content(404, "#{path} was not found.")
end
end
end
require 'bennet'
Bennet.get "/blog" do
"This is a blog"
end
Bennet.get "/hi" do
"Hello there"
end
Bennet.get "/hi/html" do
"<html><head><title>Hi</title></head><body><p style=\"color:red\">This is an HTML Hi</p></body></html>"
end
run Bennet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment