DEV Community

DevSiddhartha
DevSiddhartha

Posted on

HTTP Request Methods

We have various HTTP Request Methods available which indicate the desired action which is performed for a resource. Let us go through some of them here -

1) GET -
HTTP GET Method, as the name suggests, requests a representation of a resource from the server. GET Method should only get the data. GET returns a representation in JSON format and an HTTP response status code of 200 (OK). In case of an error, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST).

2) POST -
HTTP POST Method is often used to create new resources. On successful creation, HTTP response code 201 is returned.

3) PUT -
HTTP PUT Method replaces the target resource with the request payload.

4) DELETE -
HTTP DELETE Method deletes a resource which is identified by filters or ID. On successful deletion, the HTTP response status code 204 (No Content) is returned.

5) PATCH -
HTTP PATCH Method is used so that we can modify the resources. This method is used to do some partial modifications to a specified resource.

We can classify the HTTP methods on the basis of idempotent and safe properties.

The safe methods are the HTTP methods that do not modify resources. For example,if we use the GET or HEAD methods on a resource URL, they never change the resource.

An HTTP method is called as an idempotent method if it can be called many times without different outcomes. It doesn't matter if we call the method one or hundred times over, the result should be the same.

Top comments (0)