RESTfulness made easy using Reststop
Reststop makes it easy(ier) to implement RESTfulness in Camping. It also adds support for format-grouped Views, ala Rails' respond_to mechanism.
To install:
gem install reststop
Or just grab it from RubyForge? at http://rubyforge.org/projects/reststop/
See http://reststop.rubyforge.org/ for documentation and examples, but here's a quick illustration of a RESTful Camping controller (for dealing with kittens):
module Foobar::Controllers
class Kittens < REST 'kittens'
# POST /kittens
def create
end
# GET /kittens/(\d+)
def read(id)
end
# PUT /kittens/(\d+)
def update(id)
end
# DELETE /kittens/(\d+)
def destroy(id)
end
# GET /kittens
def list
end
end
end
Rendering views for different formats (i.e. HTML, RSS, XML, etc.) is also easy:
module Foobar::Views
module HTML
def foo
html do
p "Hello World"
end
end
end
module XML
def foo
tag!('foo')
"Hello World"
end
end
end
end
(see http://reststop.rubyforge.org/classes/Camping/Controllers.html for details on RESTful controllers)
Then when you call render in your controller, you can specify the format module as the second parameter:
render(:foo, :XML)
(see http://reststop.rubyforge.org/classes/Camping.html for details on rendering)
Camping's Blog, RESTified
For a complete example of a Reststop app, have a look at:
http://reststop.rubyforge.org/svn/trunk/examples/blog.rb
This is a RESTified version of the canonical Camping Blog app.
