In learning Ruby on Rails I have heard over and over again about RESTful resources. They are mentioned in every text, they were mentioned in my course, they are mentioned online …but I found the concept hard to grasp. In most learning environments it was glossed over, so I assumed everyone else understood it but me.
It appears to be an abstract concept, so the explanations are all abstract – but here I go trying to make a simpleton explanation for simpletons. Considering I don’t fully understand it myself, this might not be correct…
What REST stands for
Representational State Transfer
What the hell does that mean?
So, as we know, browsers initiate requests to servers, servers process requests and return appropriate responses. These requests and responses are built around the transfer of representations of resources.
A resource is whatever it is that you want to see. So it could be a book, a user, a product, whatever.
A representation, is just the document that captures and displays the state of that resource.
Representational State Transfer describes how the application will show you the different ‘states’ of the resource you want.
But what does that actually mean for my app?
It seems to mean that in RESTful applications, resources will be identified by a persistent identifier (i.e. the URI will always be the same for a resource.)
These resources will be able to be manipulated using a common set of verbs: the HTTP ones we use in Ruby on Rails are POST, GET, PUT and DELETE. (Which are like Create, Retrieve, Update, Destroy).
You should also be able to access multiple format representations of the same data (i.e. both a JSON and an XML representation of a blog post).
What do you think? Is that right?