HTTP request methods are used to request an action that you want the server to perform on the given URL address. Let us understand this with the help of a real-life situation:

  • For example, when you perform a Google search (intended action), the search engine sends your search parameter to its server using the GET HTTP request.
  • Then, the server uses the search query to find the search results (resource) and these results (response data) are then sent back to you.

An HTTP request method has a message head and a message body. The head consists of the URL and the headers, whereas the body consists of the information to be sent. 

These are the following HTTP request methods:

  • GET
  • POST
  • PUT

Let’s understand these methods in some detail.

The GET method is used to request a particular resource from a server. The response could be any data ranging from a CSS file to a JSON object. Following are some features of GET method:

  • A GET request does not have a message body; the information is sent through the message head. This makes the GET request very special.
  • It is excellent for requests that are just supposed to optionally send some information to a server and receive an output based on this information.
  • The GET request is similar to the read operation you perform on a database.

Following are some examples of a GET request:

  • Search queries
  • Fetch a specific file from a server

For example, when you enter the name of a country in a form, the list of cities in that country appears automatically. In this case, when you choose a country, a GET request is sent to the server, asking it to send you a list of the cities in that country.

As the name suggests, POST requests are used to post data to a given URL. They can be used to make the server store some entries such as the data you fill in the signup form on a website or the open text answers you write on our platform; these are all sent to the server in a POST request. Following are some features of POST method:

  • A POST request has a message body in addition to a message head. The body carries the message, which can be a JSON object or even a file.
  • The POST method is similar to the create operation you perform in a database.
  • The information you send through a POST request is neither stored in the browser nor is it cached. This makes it more desirable for sending sensitive information such as passwords or financial data. The information is stored after following proper encryption mechanisms.

At this point, it is important to understand the difference between GET and POST.

The PUT request is a special request which performs a function similar to a POST call. But this raises the question — why do you need a PUT call? The reasons and use cases for PUT are as follows:

  • PUT calls are idempotent. PUT calls instruct the server to delete the existing resource and put the resource sent in the PUT request there.
  • This is important in cases where you do not want an overlap of data. PUT calls are similar to the update operation in a database.
  • Whenever you need to update some data, you use a PUT request.

The PATCH request can be understood as something similar to the ‘update’ function. While PUT request completely modifies the entire resource, PATCH request only modifies the part of the resource that needs to be updated. Also, PATCH calls are not necessarily idempotent.

To understand the difference between PUT and PATCH, let’s consider the following image:

Suppose a person is working in the company ‘Appzroot’ and the location of work is ‘Bengaluru’.
Now, his/her location of work has to be changed to ‘Mumbai’.
If you use the PUT method to update the details, you will have to send the complete resource, i.e., {“company”: “Appzroot”, “location”: “Mumbai”} since the PUT request will overwrite the complete resource.
However, if you use the PATCH method, you will only need to send the resource that needs to be updated, i.e., { “location”: “Mumbai”}.
This is because the PATCH request will only update what has been passed in the request.

A DELETE request does exactly what its name suggests — it asks the server to delete some data from the given URL. A DELETE request, much like a GET request, does not contain any message body.
A DELETE request is quite similar to the delete operation one performs on a database.