Motivaton
This topic is being asked in so many interviews earlier i was not able to understand why anyone wants that but now i understood the need, that we should know the underline priniciples of REST.
What is REST
REST stands for Representational State Transfer , it is an architectural style , presented by Roy Fielding in 2000, and it has some priniciples and contraints that needs to be followed if we want to develop restful services.
PRINCIPLES
- Uniform Interface : 1.1 : identification of resource : every resource should have unique id 1.2 : manipulation of resource : API users should be able to modify the resources.
- Client-Server : It is a design pattern that implements that separation of Concerns means that the client lets say web app can be developed individually without worrying about the backend , and backend can be develop independently means , it does not care it is consumed by which client,
Stateless : every request should be independent means every request should be complete and does not depends on any other information
Cacheable : It is the duty of the developer to make the response cacheable or non cacheable so that the information can be stored in client side for the future calls.
- Layered System
in the above example Stateless -->is equivalent to Scaling and Cacheable is equivalent to performance
Lets understand by examples
here flavors is basically a resource.
lets understand by an example
Request ---> Response
Request : hashnode.com/api/posts
Request : endpoint, headers, params, body Response : array of objects that is the posts data
Lets say we wants to update the posts
We will create a PUT Request : hashnode.com/api/posts/1
int he request we will send the body of the request and then the response will give that the body is updated.