No commit activity in last 3 years
No release in over 3 years
Generates RESTful routes for the models of a Sinatra application (ActiveRecord, DataMapper, Stone)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0.3.1
>= 0.9.0.5
 Project Readme

Sinatra-REST

Actually it’s a set of templates to introduce RESTful routes in Sinatra. The
only thing for you to do is to provide the views. The routes and some
url helpers will be provided behind the scenes.

Installation

Guess what!

sudo gem source —add http://gems.github.com sudo gem install blindgaenger-sinatra-rest

Usage

Of course you need to require the gem in your Sinatra application:

require ‘rubygems’ require ‘sinatra’ require ‘sinatra/rest’

It’s very similar to defining routes in Sinatra (get, post, …). But this
time you don’t define the routes by yourself, but use the model’s name for
convention.

For example, if the model’s class is called Person you only need to add this
line:

rest Person

Which will add the following RESTful routes to your application. (Note the
pluralization of Person to the /people/* routes.)

  • GET /people
  • GET /people/new
  • POST /people
  • GET /people/:id
  • GET /people/:id/edit
  • PUT /people/:id
  • DELETE /people/:id

But the real benefit is, that these routes define a restful standard behaviour
on your model, appropriate routing and redirecting and named url helpers.

For instance, you can imagine the following code to be added for the /people
and /people/:id routes.


# simply add this line

rest Person, :renderer => :erb

# and this is generated for you

get '/people' do
  @people = Person.all
  erb :"people/index", options
end

put '/people/:id' do
  @person = Person.find_by_id(params[:id])
  redirect url_for_people_show(@person), 'person updated'
end

# further restful routes for Person ...

That’s only half the truth! The routes are generated dynamically, so all
defaults can be overridden (the behaviour, after/before callbacks, used renderer,
which routes are added).

For more details and options, please have a look at the pages in the
Sinatra-REST Wiki on Github.

Links

Contact

You can contact me via mail at blindgaenger at gmail dot com, or leave me a
message on my Github profile.