HTTP Request Methods

HTTP Request Methods

Introduction

It has just been 2 months since I started my Back End Web Development journey, and since then I wanted to document whatever I have learned in the form of blogs. And this is the first of many. This article primarily discusses which types of HTTP requests are most commonly used by client-side applications and their properties. So without further ado, let's start learning!

What is HTTP?

Before learning about the different types of HTTP methods, we must understand HTTP itself. So, what exactly is HTTP?

HTTP stands for Hypertext Transfer Protocol. It is a data transfer protocol for the application layer, aimed at transmitting hypermedia documents, mostly HTML documents.

HTTP was originally designed for transmitting data between a web client and a web server. From this, as you might have already figured out, we can understand that HTTP follows the classical client-server model.

One more interesting fact about HTTP is that it is a stateless protocol, which means that no state is retained by the server in between 2 client requests.

Now, that we have a basic understanding of HTTP, let us move on to what HTTP methods are.

What are HTTP methods?

To put it simply, HTTP methods are those request methods that carry out certain specific tasks with the data present in the server. When a client makes an HTTP request, the back end detects what type of method has been requested by the client, and provides the corresponding response.

Now, the responses vary depending on the request method type. The following are the request method types that are most commonly used by client-side applications (at least the ones that I am familiar with):-

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

Let's understand these methods one by one.

The Definitions

GET

The GET method is used only when we need some data representations from the server. This method should not change any data nor add any new data to the database, it should only return the requested forms.

Use Case: -

  • The data that Hashnode shows to you when you request for listing all your published articles

POST

The POST method is used when the client wants to add any new resource to the server. In this HTTP request, the client must send a request body containing the data for the resource to be added to the server database.

Use case:-

  • Whenever you sign up or register for a website, you are requesting the server to add your details, to the database.

PUT

The PUT method is used when the client wants to update the existing data representation of a target resource.

Use case:-

  • The most common use case would be when any user in a social media application, updates their profile, then the resource corresponding to the user's unique ID will be updated in the back-end server

PATCH

The PATCH method also updates data but relates to partial modifications.

Use case:-

  • Changing or resetting your password for a website or app

DELETE

The name itself gives us an idea of what the DELETE method does. It deletes the specified resource from the server database.

Use case:-

  • When you delete one of your article drafts from Hashnode, then that targeted draft is removed from the back-end database

Conclusion

These are primarily the most common HTTP request methods that you will come across as a developer, especially if you are a client-side developer. Server-side developers are required to build the logic for data transfer depending on the type of request method.

There are also the following methods, but these are lesser known and less used:-

  • HEAD
  • CONNECT
  • OPTIONS
  • TRACE

You can learn more about these HTTP request methods and their use from the MDN docs.


Finally, I would suggest going through the MDN docs as linked above, for more information on HTTP requests, and corresponding methods. These are the basic concepts that you need to learn as a developer, whether you are a client-side or a server-side developer.

This brings us to the end of this article. Do consider subscribing to my newsletter so that every time I post a new article, you get notified of it through email. I will post more content on Back End Web Development, Programming Languages, and Developer Tools.

You can also follow me on:-

Keep Learning, Ciao!