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

Learning a new framework from scratch is hard

You invested thousands of hours learning Rails and how to master its features to build web applications. This book will help you to learn Phoenix, using the knowledge you already have.

Get the book