<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>cfis : REST Controller for RAILS</title>
    <link>http://cfis.savagexi.com</link>
    <atom:link rel="self" type="application/rss+xml" href="http://cfis.savagexi.com/2006/03/26/rest-controller-for-rails?format=rss"/>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Charlie Savage's Blog</description>
    <item>
      <title>Comment on REST Controller for RAILS by Peter Williams</title>
      <description>&lt;p&gt;I posted a response to this at &lt;a href="http://pezra.barelyenough.org/blog/2006/03/another-rest-controller-for-rails/" rel="nofollow"&gt;http://pezra.barelyenough.org/blog/2006/03/another-rest-controller-for-rails/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 27 Mar 2006 17:04:18 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:e351c619-3bfd-41b8-b009-94170096b5df</guid>
      <link>http://cfis.savagexi.com/2006/03/26/rest-controller-for-rails#comment-57</link>
    </item>
    <item>
      <title>Comment on REST Controller for RAILS by Dan Kubb</title>
      <description>&lt;p&gt;Hi Charlie,&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m glad you and Peter are working on this, the different perspectives are interesting to read.&lt;/p&gt;

&lt;p&gt;From what I can tell its only the three of us looking at RESTful per-HTTP method dispatching in Rails &amp;#8211; would you (and Peter) be interested in collaborating?&lt;/p&gt;

&lt;p&gt;On your specific implementation: my original Rails Rest Controller has a nearly identical API to yours. (with small cosmetic differences of course)  You referenced my third interation in your post, but the first two are somewhat similar to yours.  Here&amp;#8217;s the announcement for RestController #1:&lt;/p&gt;

&lt;p&gt;  &lt;a href="http://microformats.org/discuss/mail/microformats-rest/2005-November/000042.html" rel="nofollow"&gt;http://microformats.org/discuss/mail/microformats-rest/2005-November/000042.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starting last fall I began developing an application around my RestController, and I found one specific problem that I think you&amp;#8217;ll run into soon since our APIs are similar.&lt;/p&gt;

&lt;p&gt;The problem is that for any given Resource, there will be a part of code where you instantiate the models.  The code will be nearly identical for each per-method handler.  (or should be, since the HTTP methods should be able to act on the same models) Your example does show a similar pattern in the Member resource, but it really won&amp;#8217;t become prominent until you&amp;#8217;re using multiple models in a single resource.&lt;/p&gt;

&lt;p&gt;To get around this I thought about making a special handler for initialization.  Instead I decided to just
use a plain rails action, and make the per-method handlers just be blocks that are executed when the request method matches, like so:&lt;/p&gt;

&lt;pre&gt;
  def collection
    conditions &amp;lt;&amp;lt; @books = Book.find(:all)

    resource.post do
      @book = @books.build(params[:book])
      if @book.save
        render_post_success :action =&gt; 'by_id', :id =&gt; @book
      else
        render :action =&gt; 'new', :status =&gt; HTTP::Status::BAD_REQUEST
      end
    end
  end
&lt;/pre&gt;


&lt;p&gt;The advantage to this is that I can wrap a block within an if statement, and restrict access to method handlers on a per user basis.   Its also less of a jump for normal rails developers and that problem you noted where the templates need to be named according to the request method goes away too.&lt;/p&gt;

&lt;p&gt;Also since each method is defined in a block, the API allows you to define response caching on a per-method basis, something I&amp;#8217;ve found really helpful in practice.&lt;/p&gt;

&lt;p&gt;After developing with the above style for the last couple of months it seems more natural than my old approach.&lt;/p&gt;</description>
      <pubDate>Mon, 27 Mar 2006 18:47:39 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:257735d9-3054-4f82-95b5-243af8ccff5a</guid>
      <link>http://cfis.savagexi.com/2006/03/26/rest-controller-for-rails#comment-58</link>
    </item>
    <item>
      <title>Comment on REST Controller for RAILS by Charlie</title>
      <description>&lt;p&gt;Hi Dan,&lt;/p&gt;

&lt;p&gt;Thanks for the very interesting comment - and it would be great to collaborate.  When I wrote this post, I wasn&amp;#8217;t aware that you had written a new version of your rest controller.  You&amp;#8217;re idea is quite intriguing, let me digest it a bit and then I&amp;#8217;ll post another article.&lt;/p&gt;</description>
      <pubDate>Wed, 29 Mar 2006 11:15:06 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:fa19430a-0f93-4f8b-9f9b-e01303ad9476</guid>
      <link>http://cfis.savagexi.com/2006/03/26/rest-controller-for-rails#comment-11</link>
    </item>
  </channel>
</rss>
