Principles of REST API
There are six basic principles of REST.
1. Stateless
The requests sent from a client to a server will contain all the required information to make the server understand the requests sent from the client. This can be either a part of URL, query-string parameters, body, or even headers. The URL is used to uniquely identify the resource and the body holds the state of the requesting resource. Once the server processes the request, a response is sent to the client through body, status, or headers.
2. Client-server
The client-server architecture enables a uniform interface and separates clients from the servers. This enhances the portability across multiple platforms as well as the scalability of the server components.
3. Uniform Interface
To obtain the uniformity throughout the application, REST has the following four interface constraints:
◦ Resource identification
◦ Resource Manipulation using representations
◦ Self-descriptive messages
◦ Hypermedia as the engine of application state
4. Cacheable
In order to enhance performance, applications are often made cacheable. This is done by labeling the response from the server as cacheable or non-cacheable either implicitly or explicitly. If the response is defined as cacheable, then the client cache can reuse the response data for equivalent responses in the future.
5. Layered system
The layered system architecture allows an application to be more stable by limiting component behavior. This type of architecture helps in enhancing the application’s security as components in each layer cannot interact beyond the next immediate layer they are in. Also, it enables load balancing and provides shared caches for promoting scalability.
6. Code on demand
This is an optional constraint and which is used the least. It permits a clients code or applets to be downloaded and to be used within the application. In essence, it simplifies the clients by creating a smart application that does not rely on its own code structure.