Use the left/right arrow keys to navigate.

Cuba

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

Sinatra


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

Cuba


on get, "articles/:id" do |id|
  article = Article[id]

  on "comments/:id" do |id|
    comment = article.comments[id]
  end
end

Not only paths can be matched


on post do
  on authenticated? do
    ...
  end

  on default do
    ...
  end
end

Composition

API = Cuba.new do
  on param("url") do |url|
    ...
  end
end

Cuba.define do
  on "api" do
    run API
  end
end

Benchmarks

Framework | Requests/s
----------|-----------
Rack      |       2217
Cuba      |       1975
Sinatra   |        950
Rails     |        535

Lines of code

Framework |        LOC
----------|-----------
Cuba      |        152
Sinatra   |       1476
Rails     |      13181

That was only ActionPack

(Rails is over 40k LOC)

More at cuba.is