Use Of Different HTTP Methods

Hi guys, hope you are all doing well!

Today, I'm stuck on something which I never thought about throughout my entire developer journey.

It's about HTTP methods. We've read about different types of HTTP methods like ๐†๐„๐“, ๐๐Ž๐’๐“, ๐๐”๐“, ๐ƒ๐„๐‹๐„๐“๐„, ๐š๐ง๐ ๐๐€๐“๐‚๐‡, and we also know they each have different purposes.

But technically, if we want to update a document in the database, we can use any HTTP method! It depends entirely on the developer's logic implemented in that route. So, this causes confusion. Why do we even have these different methods? (We all have a sense that ๐†๐„๐“ is used for fetching data from the server.) But what about ๐๐”๐“, ๐๐€๐“๐‚๐‡, ๐š๐ง๐ ๐๐Ž๐’๐“? What's their real purpose?

Finally, I understood: there is no strict technical limitation between these methods. The key difference lies in using them according to standard conventions. According to RESTful APIs, we must follow specific rules to clearly express our intent. For instance:

- ๐ˆ๐Ÿ ๐ฐ๐ž ๐ฐ๐š๐ง๐ญ ๐ญ๐จ ๐œ๐ซ๐ž๐š๐ญ๐ž ๐๐š๐ญ๐š, ๐ฎ๐ฌ๐ž ๐๐Ž๐’๐“.
- ๐ˆ๐Ÿ ๐ฐ๐ž ๐ฐ๐š๐ง๐ญ ๐ญ๐จ ๐ซ๐ž๐ฉ๐ฅ๐š๐œ๐ž ๐œ๐จ๐ฆ๐ฉ๐ฅ๐ž๐ญ๐ž ๐๐š๐ญ๐š, ๐ฎ๐ฌ๐ž ๐๐”๐“.
- ๐ˆ๐Ÿ ๐ฐ๐ž ๐ฐ๐š๐ง๐ญ ๐ญ๐จ ๐ฉ๐š๐ซ๐ญ๐ข๐š๐ฅ๐ฅ๐ฒ ๐ฎ๐ฉ๐๐š๐ญ๐ž ๐๐š๐ญ๐š, ๐ฎ๐ฌ๐ž ๐๐€๐“๐‚๐‡.

Additionally, browsers optimize these requests according to their behavior. For example, POST or other update requests are never cached. Moreover, REST clients might get confused if you write update logic inside a POST request.

In short, itโ€™s about meaning, not limitation.

Final Answer: Clearly communicate intent, follow standards, and avoid confusion.

Thank you for your time reading this ๐Ÿ˜Š.
If you have any suggestions regarding this comment, let's learn together!

0
Subscribe to my newsletter

Read articles from Hari Krishnan P U directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Hari Krishnan P U
Hari Krishnan P U