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:
GET
method requests data from the resource and should not produce any side effect.
E.g/companies/3/employees
returns list of all employees from company 3.POST
method requests the server to create a resource in the database, mostly when a web form is submitted.
E.g/companies/3/employees
creates a new Employee of company 3.
POST
is non-idempotent which means multiple requests will have different effects.PUT
method requests the server to update resource or create the resource, if it doesn’t exist.
E.g./companies/3/employees/john
will request the server to update, or create if doesn’t exist, the john resource in employees collection under company 3.
PUT
is idempotent which means multiple requests will have the same effects.DELETE
method requests that the resources, or its instance, should be removed from the database.
E.g/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.