Skip to content

axic/sinatra-jsend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Links

License

See LICENSE for details.

About

JSend helper for Sinatra

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages