A Brief Introduction to HTTP Methods

A Brief Introduction to HTTP Methods

·

3 min read

Table of contents

  • What is HTTP Request?
  • HTTP Methods

Ever wonder what happens when you search for something on Google. Let's say you search YouTube.com on Google. As soon as you hit YouTube.com on google, you make a request to the server. In simple words, a request is asking for something. Like, if you're asking Google, hey google see if you have something like Youtube.com. This is you making a request to the Google server. Google comes up with the answer, hey I found this. This is a response from google.

There are pre-defined methods for making a request. For example, you won't be using the same method for search and filling forms. The methods indicate the desired action to be performed for the given resource. The HTTP request methods are sometimes called HTTP verbs also.

HTTP Methods :

  • GET Method
  • POST Method
  • PUT Method
  • PATCH Method
  • DELETE Method

GET Method:

Get is used to request the data from the webserver. This is the main method for retrieving the results. In the GET method, query parameters are sent from the URI/URL. When you're searching for something on the internet you are using GET Method. Let's say you have API with /college/students endpoint. Making the GET request to that endpoint should return a list of all available students in the college.

Few important things about GET method:

  • Get request can be cached.
  • Since parameters are passed from URI, it has length restrictions
  • Get Request remains in the browser history.
  • Get requests are used to read and request data.

POST Method:

POST requests are used to send data to the webserver to create the resource. In the POST method, the data is passed in the body of the HTTP request. When you are filling any form, uploading profile picture or uploading file then it's the POST method that take your request to the webserver.

Few Important things about the POST method:

  • Data is passed through the body of the HTTP request.
  • POST method is used to create resources on the webserver.
  • POST requests do not remain in the browser history.
  • POST requests have no restrictions on data length.

PUT Method:

The PUT method is similar to the POST method, the PUT method is used to send data to the server to update or create resources. When you change your name, profile photo or something else from websites it's the PUT method serving you behind the scenes.

PATCH Method:

It is one of the less known methods. The PATCH method is only used when applying partial modifications to the resource. Let's take an example here, you have /college/students/{student_id} endpoint and each student has their email. With the patch request, you only need to send the updated email in the request body.

DELETE Method:

DELETE Method is self-explanatory, it does exactly as it sounds. The DELETE method deletes the resource at the specified URI. Let's say you have /college/teacher/{teacher_id} endpoint. This endpoint will be used to delete the resource using the teacher_id.

Above are the most common HTTP methods, there are other methods like HEAD, OPTIONS, CONNECT, TRACE. You can read those on Wikipedia. I have explained it briefly here, feel free to explore more and go in-depth about each method.