all repos — h3rald @ 30e0d83d11af833c3305d4995573bc244c6280f6

The sources of https://h3rald.com

content/articles/to-rest-or-not-to-rest.textile

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
----- 
permalink: to-rest-or-not-to-rest
filters_pre: 
- redcloth
title: To REST or not to REST?
comments: 
- :date: 2007-09-24 11:51:45 +02:00
  :author: Matt Beedle
  :url: http://matt-beedle.com
  :id: 85
  :body: |-
    Interesting article.  Just a couple of points I would like to make.
    
    First of, you mention URLs.  It'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: http://best-mobile-phones.org.uk/manufacturers/LG/phones/KE850-Prada/offers
    
    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: http://matt-beedle.com/2007/07/17/custom-rest-routes/
    
    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).
- :date: 2007-09-24 11:57:44 +02:00
  :author: dates
  :url: ""
  :id: 86
  :body: 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.
- :date: 2007-09-24 12:01:27 +02:00
  :author: MS
  :url: ""
  :id: 87
  :body: |-
    Have you seen how Microsoft is suggesting to encode their nextgen REST SDK?  Ugly.
    
    http://astoria.mslivelabs.com/Overview.doc
- :date: 2007-09-24 12:04:32 +02:00
  :author: browsers
  :url: ""
  :id: 88
  :body: can in fact do different HTTP commands (WebDAV).  This is how Outlook Web Access works.
- :date: 2007-09-24 23:29:42 +02:00
  :author: Fabio Cevasco
  :url: http://www.h3rald.com
  :id: 90
  :body: |-
    @Matt
    
    Thanks for your comment. I bookmarked your article for later use. May I ask why your site is _mostly_ RESTful? What couldn't you use REST for? That's what I keep noticing: people end up doing sites which are _not_ 100% RESTful... why?
- :date: 2007-09-25 05:00:31 +02:00
  :author: Matt Beedle
  :url: http://matt-beedle.com
  :id: 91
  :body: "Hi Fabio,\n\n\
    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.  \n\n\
    A more viable approach could be to create a foo controller with custom routes for each page.  However, this is unnecessary.\n\n\
    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't fit, don't use it. A site doesn'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 \"When should I REST\" would be more apt.\n\n\
    Apologies for the long rambling post! "
- :date: 2007-11-28 15:45:44 +01:00
  :author: Plop
  :url: ""
  :id: 139
  :body: |-
    Nobody asks you to use integer as id :)
    
    /users/plop
    
    meaning params[:id] == "plop"
    
    class User < AR::Base
      def self.find(*args)
        if args.first.is_a?(String) and !args.first.numeric?
          find_by_username(args.shift,*args) or raise ActiveRecord::RecordNotFound
        else
          super
        end
      end
    
      def to_param
        username
      end
    end
- :date: 2007-11-28 16:00:16 +01:00
  :author: plop
  :url: ""
  :id: 140
  :body: |+
    oooh nasty code display in my previous comment...
    
    that's better: http://pastie.caboo.se/123207
    
    
    then write user_path(user) or user_path(user.login)
    
    
date: 2007-09-24 05:48:00 +02:00
tags: 
- rails
type: article
toc: true
-----
Lately I've been reading quite a bit about Rails' REST approach, and to be totally honest I'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.

Let's see...

h3. Key Benefits

To cut a long story short, from my understanding REST can be a good thing because:

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

h3. Downsides?

Let's now try to summarize what made me think more carefully this approach...

* While I really like Rails' 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.
* URLs aren't that pretty anymore. While "someone":http://themysteriouswaysofruby.blogspot.com/2007/04/pretty-restful-urls-in-rails.html suggested a way to improve the way RESTful URLs look, that sounds like extra hassle to me. It's subjective, I know, but I really don't like using IDs in the url... I'd rather go for an univocal code any day (check out this site... I don't even like dates in my blog). 
* 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 CRUD operations, modeling a search action or authentication may be a bit tricky and may also feel a bit forced. Again, maybe it's just me.
* It may be a bit too early to take full advantage of this approach. PUT and DELETE are simulated, and this doesn't sound right -- agreed, that's the only way for now, but it still sounds like a forceful workaround. Browsers are not RESTful (yet)!
* All resources are virtually accessible by a URL. I'm not a security expert, but this scares me a bit.

Here are some posts which made me think a bit:

* "Looking for a good argument against REST":http://gilesbowkett.blogspot.com/2007/04/looking-for-good-argument-against-rest.html

* "RESTful Myths: Unraveling the Confusion":http://www.ipbabble.com/2007/07/restful_myths.html

* "Why Can’t Web Apps Be REST-ful?":http://blog.livollmers.net/index.php/2007/06/26/why-cant-web-apps-be-rest-ful/

The bottom line is: is REST 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? 

In other words, is REST really the answer to everything or in _some cases_ it is just _not necessary_? 

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 REST now. Is that true, or is there still room for -freedom- other views?

Looking forward to hear your comments, but please be nice and civilized!