In, this post we are going to discuss different types of HTTP methods available and their usage.
HTTP methods are the set of requests that indicate the desired action to be performed for a given resource. These request methods are also referred to as HTTP verbs.
The most commonly used HTTP methods are POST, GET, PUT and DELETE. These correspond to create, read, update, and delete (or CRUD) operations (in making REST API calls).
Now, let's explore all the request methods available.
The GET request is used to retrieve the data from the server accessed using a URL. The GET request is ready only type request and does not perform any kind of read/update operation on the server.
It can be cached and can be sorted in browser history. Sensitive data should never be passed using the GET method.
The POST request method is used to send data to the server to create a new resource. POST methods send the data in plain text format and data is not visible in the URL. Note, without SSL, a POST request is just as secure as a GET request, as it also gets sent unencrypted over the network).
POST method is non-idempotent meaning identical POST requests multiple times can create the same resource multiple times.
The PUT method is used to send data to a server to update the already existing resource entirely. The PUT request can also we used to create a resource like POST but the difference between two is that the PUT is idempotent i.e, calling the same PUT request multiple times will always produce the same result, unlike POST where repeated requests will create the same resource multiple times.
As the name symbolizes, the DELETE method is used to delete a resource. The DELETE requests are idempotent meaning if we DELETE a resource, it’s removed and repeatedly calling DELETE on that resource ends up the same: the resource is deleted.
TRACE methods provide a debugging mechanism to the client by echoing the received request so that a client can see what (if any) additions or changes have been made by intermediate servers.
The OPTIONS method describes the communication options for the target resource. It allows the client to find out HTTP methods and other options supported by a web server.
The CONNECT method creates a two-way communication with the requested resource. It can be used to open a TCP/IP tunnel usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.
The PATCH method is used to partially update a resource. The difference between HTTP PUT and PATCH method is that the PUT method allows only a complete replacement of the resource. Also, the patch method is not idempotent i.e, multiple identical patch requests may have different effects.
Did, I miss something or do you want to add some other key points?🤔
Please comment. 😊
If you are interested in learning HTTP response codes too, which I highly recommend. Check out this post.
This post was originally published at nlogn.in