or

RESTful Rails

I’m sure every Rails developer comes across with this term. However, most Rails beginners don’t even know what REST means. Yeah, we all know that it is an acronym for Representational State Transfer, but what exactly is this?

What is REST

The term was introduced by Roy Fielding in his Ph.D. It basically describes the architecture paradigm for web applications that request and manipulate web resources, using the standard HTTP methods such as GET, POST, PUT and DELETE. You can think REST as a sentence, all HTTP methods as verbs, and all URIs are nouns.

If I sum up a little bit more; it is absolutely not an architecture, and not tied to the Web. It is a set of design criteria and very general. REST context contains resources which can be represented in the form of HTML, XML or RSS. And for me the most important part of REST is that all REST URLs are unique, and they point to a resource(s). Resources can be anything like a document, or a row in a database, or maybe a result of an algorithm. It can be even a physical object or an abstract concept.

RESTful Rails?

Well, to me Rails is not RESTful, it just supports and suggests RESTful design. You can easily create a non-RESTful design buy creating some bad-designed code. The reason why I say Rails is not RESTful, because you should follow best design practices. Your domain models and controller classes should be in harmony. For instance:

POST /users/add
GET /pictures/3

<

p> These would fit all in RESTful design. But if you look at the following design, it is not a like that:

GET users/1?activated=true

For me the rule of thumb is your design should be readable. I’ll continue discussing on this topic later on. For now, I’ll stop since the tile is RESTful Rails only :) For those who wonders how Rails can be designed really RESTful, I like Eric Berry’s CRUD example:



Leave a Reply

Name (required)
Mail (required)
Website