Reststop makes it easy to write RESTful[http://en.wikipedia.org/wiki/Representational_State_Transfer] applications in Camping[http://github.com/camping/camping].
For info and downloads please see github.com/camping/reststop
- Authors
-
Matt Zukowski and Philippe Monnet (see github.com/camping/reststop/commits/master)
- Copyright
-
Copyright © 2010 Urbacon Ltd.
- License
-
MIT License
For an example of a complete Reststop-based Camping app, have a look at github.com/camping/reststop/blob/master/examples/blog.rb
Reststop essentially gives you three things:
1. Camping controllers that respond to the standard REST verbs:
-
create (POST)
-
read (GET)
-
update (PUT)
-
destroy (DELETE)
-
list (GET)
Custom actions are also possible. See the Reststop::Controllers#REST method documentation for usage info.
2. Camping views grouped by output format:
Your views module:
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
Your render call:
render(:foo, :XML)
See the Camping#render method documentation for usage info.
3. Nice URLs to bring it all together:
For example a list of kittens in the default format (HTML) is available at:
/kittens
The list, in RSS format:
/kittens.rss
Kitten with id 1, in XML format:
/kittens/1.xml
Using custom action ‘meow’ on kitten with id 1:
/kittens/1/meow
In other words, say you have a “kittens” resource; you can make a GET request to yourapp.com/kittens.xml and get a list of kittens through your Kittens controller’s list
, formatted using your XML
view module.
Looking for Restr, the very simple REST client?
Due to its popularity, Restr, the “very simple rest client”, has been moved out to its own gem. Restr now lives under rubyforge.org/projects/restr/ and can be installed using:
gem install restr
Restr is basically a wrapper around Ruby’s Net::HTTP, offering a more RESTfully meaningful interface.
See the “Restr documentation” for more info, but here’s a simple example of RESTful interaction with Restr:
require 'restr' kitten = Restr.get('http://example.com/kittens/1.xml') puts kitten['name'] puts kitten['colour'] kitten['colour'] = 'black' kitten = Restr.put('http://example.com/kittens/1.xml', kitten)
Copyright © 2010 the Contributors (see github.com/camping/reststop/commits/master)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.