DEV Community

Aneesh Makala
Aneesh Makala

Posted on

Why we need to represent a state transfer

REST(Representational State Transfer) has pretty much become the norm now. But, as with anything else, it's crucial to understand its motivation. Why did we come up with REST? What was the situation before REST?

Well, picture this - This is the 90s. You've built software that interacts with the oracle database. All's well. You have the desktop application installed on all the computers of your company. It comes bundled with oracle client libraries and everything's running smoothly.

Now, oracle releases a new version of their database that include some critical security bug fixes. You have no choice but to upgrade. You update your code to use the newer version of oracle. Maybe that merely involves a version change, or maybe there are some backward incompatible changes which force you to rewrite few lines of code. You take the database down, upgrade it, and then push out your software update. Now, you need to make sure that all the computers use the latest version of your software, otherwise they won't work (since you have upgraded the database). You make sure you install patches on all the machines, and only then, you can go back to sleep, hoping that you didn't break anything. It's ok, don't worry. I'm sure you've followed test driven development practices strictly.

Well, if you look at this situation closely, you'll realise that there is a tight coupling between the client application and the server. The client is very aware of the version of the database used by the server. This is a clear breach of separation of concerns. So, what do we need? Hmm, it would be nice if client could just express what it needs via some standard protocol and get the information back in some particular format, without having to worry about how the server retrieved that information.

Well, that's what REST is. It's the transferring of "representations" of resources. As opposed to directly dealing with the resource, you deal with "representations" of it. You use a "representation of a resource" to transfer resource state which lives on the server into application state on the client. You make a GET HTTP request with an id (the representation of the resource that you want), and retrieve the complete state of the resource that the server is aware of.

Such a separation of concerns is what made it possible to achieve high scale. For example, it doesn't matter if you're building an application for a mobile, a desktop or a tablet, you can use the same representations to send and receive data.

Sources

Top comments (0)