Introduction
Representational State Transfer (REST) is an architectural style that abstracts the architectural elements within a distributed hypermedia system. It was first presented by Roy Fielding in 2000.
The REST architectural style describes six constraints applied to the architecture which are described below:
Client–Server
This princples is based on separation of concerns principles. It is about separating client interface from data storage concers. This means client (facing) application should not handle data storage or management activity while server should not handle user interface or user state or how user is interacting with the application.Since both the client and server are independent of each other. They can be developed independently and will be more manageable and scalable.
Stateless
Server should not store any client context information. Each client request shuould contain all the necessary information to handle the request. Session state should be held in the client
Cacheable
Client can cache responses. Response can be, implicitly or explicitly, labeled as cacheable or non-cacheable. So that client can reuse the same response data in future for equivalent request.
Layered system
It allows to use multiple hierarchical layers to compose the application. e.g. API can be deployed to Server X, database on Server B etc.
A client cannot ordinarily tell whether it is connected directly to the end server, or to an intermediary along the way.
Intermediary servers may be useful in load-balancing, cache management, security etc.
Code on demand (optional)
Servers can temporarily extend or customize the functionality of a client by the transfer of executable code. Examples of this may include compiled components such as Java applets and client-side scripts such as JavaScript. "Code on demand" is the only optional constraint of the REST architecture.
Uniform interface
The uniform interface between clients and servers, simplifies and decouples the architecture, which enables each part to evolve independently. The four guiding principles of this interface are detailed below.
- Identification of resources
- Resource manipulation through representations
- Self-descriptive messages
- Hypermedia as the engine of application state