REST – Representational State Transfer


REST is a concept that has been becoming very popular over the last few years, probably helped by the embrace it is receiving from the Rails community. When you do something RESTfully, you are performing actions on a resource. There are four basic actions that we might want to use on a resource: create it, read/view it, update it, and delete it. Sometimes this is called CRUD.

These four actions relate very nicely to four HTTP methods. Most web developers know about GET and POST. When we view anything on the Internet we are normally using the GET method to get something from the web server. When we fill in a form and submit data to the web server, we are usually using a POST method. I think that’s why we say ‘blog post’ because it is something we have literally POSTed to the Internet. But there are two other methods that we can use: PUT for when we get something, change it, and put it back, and DELETE for the last of the four CRUD actions.

So we apply the HTTP methods to the resource, indicated by a URI. The point is that the URI stays the same. Suppose i have a resource which is a task, uniquely identified by this URI:

http://site.com/tasks/1

If i GET that URI then i am viewing the task. If i PUT to it then i am updating it. If i send a DELETE request to that same URI then the server will know that i wish to delete the resource.

Cheers

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s