This is what I think of REST architecture.
For every resource, there is an unique URI.
We can manipulate that object using its URI and HTTP actions [POST, GET, PUT and DELETE]. The HTTP request transfers the representation of the state of that object.
In all the texts I have read, REST is explained in a weird and confusing manner.
One more thing, RESTFUL implementation in rails produces different urls for different purposes. Like /teams -> for 'index' method... /teams/new -> for 'new' method and so on. Ain't this moving away from rest, which defines that each resource has one unique URI???
A REST API is an application programming interface (API) that uses a representational state transfer (REST) architectural style. The REST architectural style uses HTTP to request access and use data. This allows for interaction with RESTful web services.
REST stands for REpresentational State Transfer and describes resources (in our case URLs) on which we can perform actions. CRUD , which stands for Create, Read, Update, Delete, are the actions that we perform. Although, in Rails, REST and CRUD are bestest buddies, the two can work fine on their own.
Representational State Transfer (REST) is an architectural pattern. The specifics of what exactly is and isn't REST is a hotly debated topic, but at it's core it defines a set of constraints for building robust distributed system (web applications in our case).
I think your understanding of REST is pretty good. It doesn't need to be any more complicated than it should be. Also @Surya outlines some very good points.
The way Rails maps the HTTP methods to controller methods is:
GET => show
PUT => update
POST => create
DELETE => destroy
Two other resources/methods that rails provides namely:
resource/new => new
resource/edit => edit
are most likely not resources for all practical purposes but are needed for building web pages and applications. If the client had full knowledge of the resource, these would not be needed. A client can just make POST
and PUT
calls with the resource information and create or update resources as needed. But since users are not expected to know the ins and outs of a resource, they need an easier interface to work with for creation or updation.
If all users were fully aware of the resources and were skillful enough with the command line, we wouldn't even need HTML. They can just curl
in their interactions with those resources :)
index
just makes it easier to work with collections. It is still a well defined resource and has a unique representation, for example /books
. How it is handled on the server side code does not make it RESTless
(I just made that up, but its awesome).
I'd start with chapter 5 of Roy Fielding's dissertation. There are a few basic principles:
I have recently answered a question on good resources to learn REST, could be helpful.
I'm not familiar with Rails, so not addressing that part of the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With