Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master

This branch is 1 commit ahead, 1806 commits behind caelum:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Quit pretending

CRUD through HTTP is a good step forward to using resources and becoming RESTFul, another step further into is to make use of hypermedia based services and this gem allows you to do it really fast.

Restfulie: client-side

Here you can see how to access a resource and its services through the restfulie API:

order = Order.from_web resource_uri      # retrieves order resource (xml/atom/json support)

puts "Order price is #{order.price}" payment                        # sends a post request to pay this order

order.cancel                             # sends a delete request

Restfulie: server-side

This is a simple example how to make your state changes available to your resource consumers:

	class Order < ActiveRecord::Base
	  def following_states
	    states = [ {:controller => :orders, :action => :show } ]
	    states << {:controller => :orders, :action => :destroy} if can_cancel?
	    states << {:controller => :orders, :action => :pay, :id => id} if can_pay?
	    states << {:controller => :payments, :action => :show, :payment_id => } if paied?


Just add in your environment.rb the following line:

config.gem "restfulie", :source => ""


rake gems:install

or, if you prefer to install as a plugin:

script/plugin install git://

Typical Restful Example

Trying to follow the definition of a restful application supporting resources with hypermedia content, a typical restful resource would be:

	<product>basic rails course</product>
	<product>restful training</product>
	<atom:link rel="refresh" href="" xmlns:atom=""/>
	<atom:link rel="update" href="" xmlns:atom=""/>
	<atom:link rel="pay" href="" xmlns:atom=""/>
	<atom:link rel="destroy" href="" xmlns:atom=""/>

Client Usage

One should first acquire the representation from the server through your common GET process and process it through the usual from_* methods:

xml = Net::HTTP.get(URI.parse(‘’))
order = Order.from_xml(xml)

And now you can invoke all those actions in order to change your resource’s state:


Note that:

  • refresh is get
  • update is put (and you have to put everything back)
  • destroy is delete
  • pay (unknown methods) is post

Resource format support

Restfulie currently supports xml+atom and will soon expand its support to xml+rel links and json+links supports. Those new formats will also support automatic http verb detection – if possible and reasonable.


If you are looking for or want to help, let us know at the mailing list:

How to customize your request

By default, restfulie uses the following table:

  • destroy, cancel and delete send a DELETE request
  • update sends a POST request
  • refresh, reload, show sends a GET request
  • other methods sends a POST request

If you want to use a custom http verb in order to send your request, you can do it by setting the optional string ‘method’:




  • Copyright © 2009 Caelum –
  • All rights reserved.
  • Licensed under the Apache License, Version 2.0 (the “License”);
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an “AS IS” BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
Something went wrong with that request. Please try again.