SinatraSimpleRouter

I open sourced SinatraSimpleRouter. I have been using it in a few projects, structuring very simple RESTFul APIs. You can see a few examples about its usage below. Feel also free to fork it on Github.

require "sinatra"
require "sinatra_simple_router"

class OrdersController
  def initialize(app)
    @app = app
  end

  def show
    @order = Order.find(params[:id])
    @app.content_type "application/json"
    @app.body @order.to_json
  end
end

# Using the builtin SinatraSimpleRouter::Controller
class ItemsController < SinatraSimpleRouter::Controller
  def show
    @item = Item.find(params[:id])
    render json: @item
  end
end

class Application < Sinatra::Base
  include SinatraSimpleRouter

  match :get, "/orders/:id.json", OrdersController, :show
  match :get, "/items/:id.json", ItemsController, :show
end

You might also like

Comparison between Rack, Sinatra and Webmachine

Benchmarking Ruby and Erlang

Healthyr - Rails app performance monitor

Open sourcing a lib I created to benchmark Rails apps, using ActiveSupport::Notifications

Download files from a FTP server using Ruby

Download free e-book

Learn different strategies on API versioning with "Versioned APIs with Phoenix" free e-book