REST endpoints become very popular in SaaS applications in recent times. We need to understand what http method used for what operation in general.
The important HTTP methods are as follows:
GETmethod requests data from the resource and should not produce any side effect.
/companies/3/employeesreturns list of all employees from company 3.
POSTmethod requests the server to create a resource in the database, mostly when a web form is submitted.
/companies/3/employeescreates a new Employee of company 3.
POSTis non-idempotent which means multiple requests will have different effects.
PUTmethod requests the server to update resource or create the resource, if it doesn’t exist.
/companies/3/employees/johnwill request the server to update, or create if doesn’t exist, the john resource in employees collection under company 3.
PUTis idempotent which means multiple requests will have the same effects.
DELETEmethod requests that the resources, or its instance, should be removed from the database.
/companies/3/employees/john/will request the server to delete john resource from the employees collection under the company 3.
There are few other methods which we will discuss in another post.