REST Architecture Introduction

1. What is REST?

REST (stands for Representational state transfer) is an architectural style for modern web introduced and elaborated by Roy Thomas Fielding in his PhD dissertation in 2000. The key goals of REST architecture is to make web applications simple, scalable and well suited for the growth of web applications.

In REST architecture style, any data, functionality or whatever entities on which the actions are performed in web is called a resource. As per Roy Fielding, whatever that can be named is a resource. For example price of a stock, a jpeg image, a music video, a product in an inventory, words of an online dictionary etc.
These resources are identified by URLS, transformed if needed and then transferred between client and server as representations such as json, xml, html, jpeg etc over an uniform interface.

REST is an architectural style that applies a set of constraints over architectural elements to induce desired properties in modern web architectures.
The constraints are provided in the table below.

S.No Constraint Constraint Definition Induced Desired properties
1 Client – Server Separating the User interface concerns from the data storage concerns (Separation of Concerns) Improve the portability of user interface across mulitple platforms and scalability of server components.
2 Stateless Stateless constraint is applied on above Client Server interaction, such that each request from client to server must contain all the information necessary to understand the request. It cannot take advantage any stored context in the server and session state should be kept entirely on the client. Improves Visibility – A monitoring system does not have to look beyond a single request data in order to determine the full nature of the request.
Improves Reliability – Eases the task of recovering from partial failures
Improves Scalability – Not having to store state between requests allows the server component to quickly free resources, and further simplifies implementation because the server doesn’t have to manage resource usage across requests.
This has some disadvantages like sending repetitive data across the network.
3 Cache Cache constraints require that the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests. Caching increases user-perceived performance.
4 Uniform Interface Uniform interface between server and client components. REST defines four interface constraints.
1.identification of resources
2.manipulation of resources through representations
3.self-descriptive messages
4.hypermedia as the engine of application state
Improves simplicity of overall system architecture. Improves visibility of interactions.
5 Layered System A layered system is organized hierarchically, each layer providing services to the layer above it and using services of the layer below it. By restricting knowledge of the system to a single layer, we place a bound on the overall system complexity and promote substrate independence. Layers can be used to encapsulate legacy services and to protect new services from legacy clients, simplifying components by moving infrequently used functionality to a shared intermediary.
6 Code on Demand (OPTIONAL) REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts. This simplifies clients by reducing the number of features required to be pre-implemented. Allowing features to be downloaded after deployment improves system extensibility. However, it also reduces visibility, and thus is only an optional constraint within REST.

2. Why this architecture is named/called “(REST) REPRESENTATIONAL STATE TRANSFER”?

In REST architecture actions are performed on a resource, by using a representation to capture the current or intended state of that resource and transferring the representation between components.

Simple example to explain this.

Lets assume a user buying a cellphone online.
When user searches for cellphones, a list of cellphones are retrieved from the server.
Now the cellphone list (resource) provided are available for sale – Now we can say the cellphones are in state 1 or the whole system (the buyer and provider) is in state 1.
This state (list of cellphones available for purchase) is now represented as xml/html/json/document/jpeg image etc and transferred from Server to the users browser.
Now the user choose a cell phone(resource) and Click buy. At this point the resource (cell phone) and whole system (the buyer and provider) moves to state 2.
This state 2, is now represented as xml/html/json/document/jpeg image etc and transferred from the browser to the server.

This way of transferring system states between components by using a representation is called “REPRESENTATIONAL STATE TRANSFER (REST)”.

%d bloggers like this: