Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
RESTful Rails | 209

Uniformity


One of the biggest advantages afforded by the REST guidelines is a uniform inter-
face. The verbs (in our case, the HTT Pmethods) are universally uniform, across all
application domains. Content types, though not universal (they differ across
domains), are standardized and relatively well known.


The fact that you are limited to such a small set of methods may seem constraining,
but in practice it is not a major concern. Anything you would want to model can eas-
ily be framed in terms of the CRUD operations. This way of thinking about the
world helps to push essential complexity into one part of an architecture, where it is
easily dealt with. Usually, when it seems that you need more than the basic meth-
ods, there is another entity lurking in the model, waiting to be extracted.


Content types are standardized in a different way. Content types are usually some-
what application-specific, and so it would make no sense for them to be universal.
However, to facilitate communication, content types are usually somewhat stan-
dard. In the HTT Pworld, this meansMIME(Multipurpose Internet Mail Exten-
sions), an Internet standard that defines a framework for content types. The set of
MIME types is extensible, so new applications can define local types and even regis-
ter them with the IANA once they are in widespread use.


The uniformity that REST provides tremendously aids standardization efforts. When
bringing multiple systems together (as happens when developing a standard), the
fewer differences there are, the fewer political disagreements. If everyone standard-
izes on a set of verbs (which are universally standardized when using HTTP), then the
only differences that remain are the content types (which are fairly straightforward to
standardize within an application domain) and nouns.


Therefore, complying with a RESTful interface helps to reduce the huge problem of
standardization to the somewhat more manageable problems of representing data
(content types) and naming things (nouns). Though these are still areas where dis-
agreement and politics can interfere, the principles of REST help to focus the discus-
sion by narrowing the topics of discussion.


RESTful Rails


At RailsConf 2006, David Heinemeier Hansson’s keynote marked the beginning of
the RESTful philosophy becoming mainstream in Rails. The keynote,Discovering a
World of Resources on Rails,*presented a roadmap for moving Rails 1.2 toward a
more RESTful, CRUD-based default.



  • Presentation slides and video available athttp://www.scribemedia.org/2006/07/09/dhh/.

Free download pdf