Representational state transfer (REST) is a software architectural style that defines a set of guidelines to be used when creating Web services.
REST provides interoperability between computer systems on the Internet as each system has to use one uniform way of interact with the API.
REST is describing the web. Before REST the architecture of the web was more or less non-existent. Representational State Transfer (REST) is a key architectural principle of the World Wide Web.
Terminology:
- Resource is an object or representation of something, which has some associated data with it ( delete, add, update).
-
The client application and server application MUST be able to evolve separately without any dependency on each other.
A client should only know resource URIs and that’s all.
-
REST is inspired by HTTP, so it reflects in this constraint.
Make all client-server interaction stateless.
Server will not store anything about latest HTTP request client made. It will treat each and every request as new.
No session, no history.
-
Cacheable
In REST, caching shall be applied to resources when applicable and then these resources MUST declare themselves cacheable. Caching can be implemented on the server or client side.
-
Uniform interface
A resource in the API should have only one logical URI and that provides a way to fetch related or additional data.
The HTTP methods (GET, POST, DELETE, PUT), also called as verbs, play the role.
When the client raises a request to the server through an API, the client should know the feedback.
The server should always return the right status code.
-
Layered system –
REST allows you to use a layered system architecture where you deploy the APIs on server A, and store data on server B and authenticate requests in Server C, for example.
Each component in the layered system cannot “see” beyond the immediate layer with which they are interacting.
- Code on demand (optional) – REST allows client functionality to be extended by downloading and executing code in the form of applets or scripts.