Cuba
Microframework for web development
Microframework for web development
require "cuba"
Cuba.define do
on "hello" do
res.write "hello, world"
end
end
run Cuba
# Sinatra
get "/hello" do
"hello, world"
end
# Cuba
on get, "hello" do
res.write "hello, world"
end
get "/articles/:id" do |id|
article = Article[id]
end
get "/articles/:article_id/comments/:id" do |article_id, id|
article = Article[article_id]
comment = article.comments[id]
end
on get, "articles/:id" do |id|
article = Article[id]
on "comments/:id" do |id|
comment = article.comments[id]
end
end
on post do
on authenticated? do
...
end
on default do
...
end
end
API = Cuba.new do
on param("url") do |url|
...
end
end
Cuba.define do
on "api" do
run API
end
end
Framework | Requests/s
----------|-----------
Rack | 2217
Cuba | 1975
Sinatra | 950
Rails | 535
Framework | LOC
----------|-----------
Cuba | 152
Sinatra | 1476
Rails | 13181
(Rails is over 40k LOC)