Sinatra::JSend

JSend output helper for Sinatra. Extends Sinatra to support the JSend proprosal.

Depends on the Sinatra::JSON helper from Sinatra-Contrib.

Installation

System install

gem install sinatra-jsend

Gemfile

gem 'sinatra-jsend', :require => 'sinatra/jsend'

Usage

Classic:

require "sinatra"
require "sinatra/jsend"

get '/' do
  jsend_fail({ :title => "A title is required" }) if params[:title] == nil
  jsend_success({ :post => { :id => 1, :title => "First entry" } })
end

Modular:

require "sinatra/base"
require "sinatra/jsend"

class MyApp < Sinatra::Base
  helpers Sinatra::JSend

  get '/' do
    jsend_fail({ :title => "A title is required" }) if params[:title] == nil
    jsend_success({ :post => { :id => 1, :title => "First entry" } })
  end
end

License

See LICENSE for details.