In the previous posts, we've discussed the general project, defined the concept of REST and taken a look at the list, show and save operations. Now, let's talk a little shop and dissect the concept of REST a bit further.
REST has some very important design concepts that need to be leveraged to be successful. First, a rich and easy interface. This is important for two reasons. Building a client implementation around a set of REST services can focus on user experience and ignore the data needs. That is to say, the data is well-defined and the developer building the client can rely on those services to provide specific data. The application will be built around that data without intermixing the client specific code.
The second important reason is, a developer can build any client around a set of REST services. Why? The data has no complicating details blurring the line between the user experience and the data. In doing so, it makes it more adaptable to move from a purely web-based client to say a mobile web client. Later, moving to a native client or game console becomes a reality. Later on down the road, the REST API is published and developers are developing custom applications, much like Twitter, Amazon and others.
Another idea I have read about but do not fully understand is the concept of idempotent resources. Idempotent is defined as an element multiplied by itself remains unchanged. The simplest case I can come up with is 1. 1 multiplied by 1 is still 1.
So how does this apply to resource in your system? Making a request to the same URI should result in the same operation time and time again. In other words, creating an entry for a book with the same title should result in the same book being created or denied every time. Only one book is created with that title. Both PUT and DELETE methods are idempotent. The GET method is also idempotent given that there are no lasting changes on the resource being requested. POST is an update operation and can result in attributes of a given resource being altered. It does not qualify as an idempotent method.
Now, we have defined why REST has good qualities. It provides a rich and easy interface to resources or decouples the client from the data, in doing so, making the data and services scalable. We have cleared up the concept of idempotent and what that means to a resource in our system.
It is important to remember that REST isn't a specification like SOAP. It is merely a suggestion of an architectural design around how to serve data. There are goals within the design to decouple data from the client so that these services are scalable, reliable and well-defined for future client implementations.