<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>H3RALD: To REST or not to REST?</title>
    <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Fabio Cevasco's Writings</description>
    <item>
      <title>To REST or not to REST?</title>
      <description>&lt;p&gt;Lately I&amp;#8217;ve been reading quite a bit about Rails&amp;#8217; &lt;span class="caps"&gt;REST&lt;/span&gt; approach, and to be totally honest I&amp;#8217;m not 100% convinced it can always be a good idea. The purpose of this post is to re-evaluate the situation, and ask other people their opinion on the matter.&lt;/p&gt;


	&lt;p&gt;Let&amp;#8217;s see&amp;#8230;&lt;/p&gt;


	&lt;h3&gt;Key Benefits&lt;/h3&gt;


	&lt;p&gt;To cut a long story short, from my understanding &lt;span class="caps"&gt;REST&lt;/span&gt; can be a good thing because:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;It introduces the powerful concept of &amp;#8220;resources&amp;#8221;, which is independent from the presentation. This basically means that you can have your &amp;#8220;resources&amp;#8221; represented in &lt;span class="caps"&gt;HTML&lt;/span&gt;. XML etc. etc. &amp;#8220;for free&amp;#8221;. If you are making an extensive use of web services, this is truly a bless. &lt;/li&gt;
		&lt;li&gt;Each &lt;span class="caps"&gt;CRUD&lt;/span&gt; action is carried out using a different &lt;span class="caps"&gt;HTTP&lt;/span&gt; command (get, post, put and delete). At present, because most browsers don&amp;#8217;t understand &lt;span class="caps"&gt;PUT&lt;/span&gt; or &lt;span class="caps"&gt;DELETE&lt;/span&gt; requested, this is somehow simulated by Rails.&lt;/li&gt;
		&lt;li&gt;By thinking and modeling your application in terms of resources, everything should always be &amp;#8220;in the right place&amp;#8221;.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Downsides?&lt;/h3&gt;


	&lt;p&gt;Let&amp;#8217;s now try to summarize what made me think more carefully this approach&amp;#8230;&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;While I really like Rails&amp;#8217; convention over configuration philosophy, this sounds a tiny bit too extreme for me. In the end it could be good, but it requires developers to completely re-think the way they develop their application in order to be 100% RESTful.&lt;/li&gt;
		&lt;li&gt;URLs aren&amp;#8217;t that pretty anymore. While &lt;a href="http://themysteriouswaysofruby.blogspot.com/2007/04/pretty-restful-urls-in-rails.html"&gt;someone&lt;/a&gt; suggested a way to improve the way RESTful URLs look, that sounds like extra hassle to me. It&amp;#8217;s subjective, I know, but I really don&amp;#8217;t like using IDs in the url&amp;#8230; I&amp;#8217;d rather go for an univocal code any day (check out this site&amp;#8230; I don&amp;#8217;t even like dates in my blog). &lt;/li&gt;
		&lt;li&gt;Sometimes, it may take quite a bit to figure out how to model some functionality using resources. While it is straightforward when you want to perform &lt;span class="caps"&gt;CRUD&lt;/span&gt; operations, modeling a search action or authentication may be a bit tricky and may also feel a bit forced. Again, maybe it&amp;#8217;s just me.&lt;/li&gt;
		&lt;li&gt;It may be a bit too early to take full advantage of this approach. &lt;span class="caps"&gt;PUT&lt;/span&gt; and &lt;span class="caps"&gt;DELETE&lt;/span&gt; are simulated, and this doesn&amp;#8217;t sound right&amp;#8212;agreed, that&amp;#8217;s the only way for now, but it still sounds like a forceful workaround. Browsers are not RESTful (yet)!&lt;/li&gt;
		&lt;li&gt;All resources are virtually accessible by a &lt;span class="caps"&gt;URL&lt;/span&gt;. I&amp;#8217;m not a security expert, but this scares me a bit.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Here are some posts which made me think a bit:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://gilesbowkett.blogspot.com/2007/04/looking-for-good-argument-against-rest.html"&gt;Looking for a good argument against &lt;span class="caps"&gt;REST&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.ipbabble.com/2007/07/restful_myths.html"&gt;RESTful Myths: Unraveling the Confusion&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://blog.livollmers.net/index.php/2007/06/26/why-cant-web-apps-be-rest-ful/"&gt;Why Can&#8217;t Web Apps Be &lt;span class="caps"&gt;REST&lt;/span&gt;-ful?&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The bottom line is: is &lt;span class="caps"&gt;REST&lt;/span&gt; really worth the hassle? Especially for small and simple applications like a blog, is it really worthwhile to coerce myself to adopt a RESTful approach when I could accomplish exactly the same things with much less hassle?&lt;/p&gt;


	&lt;p&gt;In other words, is &lt;span class="caps"&gt;REST&lt;/span&gt; really the answer to everything or in &lt;em&gt;some cases&lt;/em&gt; it is just &lt;em&gt;not necessary&lt;/em&gt;?&lt;/p&gt;


	&lt;p&gt;And also (OK, this may sound harsh and impolite): does it really make sense to push people to adopt a RESTful approach no matter what? Sometimes someone may get the feeling that Rails is all about &lt;span class="caps"&gt;REST&lt;/span&gt; now. Is that true, or is there still room for &lt;del&gt;freedom&lt;/del&gt; other views?&lt;/p&gt;


	&lt;p&gt;Looking forward to hear your comments, but please be nice and civilized!&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 05:48:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:29e25458-02bf-48bc-925d-5d0841d75392</guid>
      <author>h3rald</author>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest</link>
      <category>Blog</category>
      <category>Rails</category>
      <trackback:ping>http://www.h3rald.com/trackback/entries/120</trackback:ping>
    </item>
    <item>
      <title>"To REST or not to REST?" by plop</title>
      <description>&lt;p&gt;oooh nasty code display in my previous comment&amp;#8230;&lt;/p&gt;


	&lt;p&gt;that&amp;#8217;s better: &lt;a href="http://pastie.caboo.se/123207" rel="nofollow"&gt;http://pastie.caboo.se/123207&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;then write user_path(user) or user_path(user.login)&lt;/p&gt;</description>
      <pubDate>Wed, 28 Nov 2007 16:00:17 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:07f4901d-e1ca-466d-931d-b89551250a80</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-140</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by Plop</title>
      <description>&lt;p&gt;Nobody asks you to use integer as id :)&lt;/p&gt;


	&lt;p&gt;/users/plop&lt;/p&gt;


	&lt;p&gt;meaning params[:id] == &amp;#8220;plop&amp;#8221;&lt;/p&gt;


	&lt;p&gt;class User &amp;lt; AR::Base
  def self.find(&lt;strong&gt;args)
    if args.first.is_a?(String) and !args.first.numeric?
      find_by_username(args.shift,&lt;/strong&gt;args) or raise ActiveRecord::RecordNotFound
    else
      super
    end
  end
end&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;def to_param
  username
end&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 28 Nov 2007 15:45:45 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:6f86d0ee-bbd9-42c9-a2be-0af3df7f119e</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-139</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by Matt Beedle</title>
      <description>&lt;p&gt;Hi Fabio,&lt;/p&gt;


	&lt;p&gt;The home page, contact-us, terms, disclaimer, etc are not RESTful.  These are just normal mapped routes as they do not really correspond to a resource.  I know it is easy for beginners to get confused when learning REST based design for the first time, I certainly did.  One could decide to create a contact_us controller, a terms controller etc, each with just a show action to render the page.  Obviously this would be overkill.&lt;/p&gt;


	&lt;p&gt;A more viable approach could be to create a foo controller with custom routes for each page.  However, this is unnecessary.&lt;/p&gt;


	&lt;p&gt;The point I am trying to make is that REST is not a mutually exclusive design methodology.  It works very well for database driven sites, and this is where is should be used.  Where it doesn&amp;#8217;t fit, don&amp;#8217;t use it. A site doesn&amp;#8217;t need to be entirely REST based.  When you think of it in these terms, the question REST or not to REST does not really fit.  Maybe something like &amp;#8220;When should I REST&amp;#8221; would be more apt.&lt;/p&gt;


	&lt;p&gt;Apologies for the long rambling post!&lt;/p&gt;</description>
      <pubDate>Tue, 25 Sep 2007 05:00:35 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:57f12806-f752-4202-9e64-e5f7b41af567</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-91</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by Fabio Cevasco</title>
      <description>&lt;p&gt;@Matt&lt;/p&gt;


	&lt;p&gt;Thanks for your comment. I bookmarked your article for later use. May I ask why your site is &lt;em&gt;mostly&lt;/em&gt; RESTful? What couldn&amp;#8217;t you use REST for? That&amp;#8217;s what I keep noticing: people end up doing sites which are &lt;em&gt;not&lt;/em&gt; 100% RESTful&amp;#8230; why?&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 23:29:43 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:228779da-88ef-4397-bf17-11a41a8c249a</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-90</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by browsers</title>
      <description>&lt;p&gt;can in fact do different HTTP commands (WebDAV).  This is how Outlook Web Access works.&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 12:04:32 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:8a448923-adfb-4e4c-806d-8b2b2365cdf7</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-88</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by MS</title>
      <description>&lt;p&gt;Have you seen how Microsoft is suggesting to encode their nextgen REST SDK?  Ugly.&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://astoria.mslivelabs.com/Overview.doc" rel="nofollow"&gt;http://astoria.mslivelabs.com/Overview.doc&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 12:01:28 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:5c0f8dad-89ff-4005-afa4-beab98a9621d</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-87</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by dates</title>
      <description>&lt;p&gt;on blogs are good.  When research a topic, sometimes it is the date stamp on a blog that lets me know if the information is too dated to consider or not.&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 11:57:45 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:a881dd5d-4258-4dae-baf8-a39017d594a8</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-86</link>
    </item>
    <item>
      <title>"To REST or not to REST?" by Matt Beedle</title>
      <description>&lt;p&gt;Interesting article.  Just a couple of points I would like to make.&lt;/p&gt;


	&lt;p&gt;First of, you mention URLs.  It&amp;#8217;s very simple to make these look nice, just using to_param, and find_by_foo.  I have a phone site which is almost completely RESTful.  Here is a once of the longest urls: &lt;a href="http://best-mobile-phones.org.uk/manufacturers/LG/phones/KE850-Prada/offers" rel="nofollow"&gt;http://best-mobile-phones.org.uk/manufacturers/LG/phones/KE850-Prada/offers&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;Secondly, although in a pure RESTful design each controller contains only 7 actions, it is easy to add other custom ones.  I have written an article about it before here: &lt;a href="http://matt-beedle.com/2007/07/17/custom-rest-routes/" rel="nofollow"&gt;http://matt-beedle.com/2007/07/17/custom-rest-routes/&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;The point of REST is more that it encourages good application design.  Thin controllers (containing little logic) and thick models (containing most of the logic).&lt;/p&gt;</description>
      <pubDate>Mon, 24 Sep 2007 11:51:48 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:536a5c81-2a7f-48e0-b200-888fc5fccee7</guid>
      <link>http://www.h3rald.com/blog/to-rest-or-not-to-rest#comment-85</link>
    </item>
  </channel>
</rss>
