Hello, I’m HTTP and these are my request methods👋🏻

😄 Introduction

HTTP (Hyper Text Transfer Protocol) is heart of all the websites and that’s one of the many reason to know the different request methods this protocol provides, be it for REST API development, a frontend dev consuming APIs or …


This content originally appeared on DEV Community and was authored by Kaustubh Joshi

😄 Introduction

HTTP (Hyper Text Transfer Protocol) is heart of all the websites and that's one of the many reason to know the different request methods this protocol provides, be it for REST API development, a frontend dev consuming APIs or even for cracking an Interview.

This post will provide you all the information you need to understand HTTP a better and a simpler way.

💻 Semantics

  1. Idempotent Methods - Methods which doesn't change state of the server even when the same (identical) request is made multiple times in a row.
  2. Safe Methods - Methods which doesn't change any resource in a server.
  3. Cacheable Methods - Methods whose response can be cached on the client side saving the REST call to the server.

Note: All SAFE methods are IDEMPOTENT but not vice versa.

📬 HTTP Request Methods

  1. GET - Represents a request for specific source. Only use to fetch data.
    • has request body - NO
    • Idempotent - YES
    • Safe - YES
    • Cacheable - YES
    • has response body - YES
  2. POST - Used to send data to the server. Ideally should use to create new resource on the server.
  3. PUT - Used to create new resource or update an existing resource with the request body containing the newly-updated representation of the original resource.
    • has request body - YES
    • Idempotent - YES
    • Safe - NO
    • Cacheable - NO
    • has response body - NO
  4. PATCH - Used to partially update data with the provided identifier, if absent it will throw an exception.
    • has request body - YES
    • Idempotent - NO
    • Safe - NO
    • Cacheable - NO
    • has response body - YES
  5. DELETE - The HTTP DELETE request method deletes the specified resource.
    • has request body - May
    • Idempotent - YES
    • Safe - NO
    • Cacheable - NO
    • has response body - May
  6. OPTIONS - The OPTIONS method describes the communication options for the target resource.
    • has request body - NO
    • Idempotent - YES
    • Safe - YES
    • Cacheable - NO
    • has response body - YES
  7. HEAD - Returns headers of the HTTP request without response body. Same as GET without response body.
    • has request body - NO
    • Idempotent - YES
    • Safe - YES
    • Cacheable - YES
    • has response body - NO
  8. CONNECT - The HTTP CONNECT method starts two-way communications with the requested resource. It can be used to open a tunnel.
    • has request body - NO
    • Idempotent - NO
    • Safe - NO
    • Cacheable - NO
    • has response body - NO
  9. TRACE - The HTTP TRACE method performs a message loop-back test along the path to the target resource, providing a useful debugging mechanism.
    • has request body - NO
    • Idempotent - YES
    • Safe - YES
    • Cacheable - NO
    • has response body - NO

Note: PUT will either update or create new resource where PATCH will always update it, if the provided identifier is absent on the server, it will throw an exception. (ex. invalid product id)

🏮 Browser Compatibility

This image is taken from here
image

👁‍🗨 Conclusion

This article should provide you a birds-eye-view of all the HTTP request methods in less than 10 mins.
I hope this post will help you in future, while choosing the correct method for your API or a last min study for your interview.

HAPPY CODING!!!❤️

Alt Text

📚 References


This content originally appeared on DEV Community and was authored by Kaustubh Joshi


Print Share Comment Cite Upload Translate Updates
APA

Kaustubh Joshi | Sciencx (2021-10-08T12:44:51+00:00) Hello, I’m HTTP and these are my request methods👋🏻. Retrieved from https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/

MLA
" » Hello, I’m HTTP and these are my request methods👋🏻." Kaustubh Joshi | Sciencx - Friday October 8, 2021, https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/
HARVARD
Kaustubh Joshi | Sciencx Friday October 8, 2021 » Hello, I’m HTTP and these are my request methods👋🏻., viewed ,<https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/>
VANCOUVER
Kaustubh Joshi | Sciencx - » Hello, I’m HTTP and these are my request methods👋🏻. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/
CHICAGO
" » Hello, I’m HTTP and these are my request methods👋🏻." Kaustubh Joshi | Sciencx - Accessed . https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/
IEEE
" » Hello, I’m HTTP and these are my request methods👋🏻." Kaustubh Joshi | Sciencx [Online]. Available: https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/. [Accessed: ]
rf:citation
» Hello, I’m HTTP and these are my request methods👋🏻 | Kaustubh Joshi | Sciencx | https://www.scien.cx/2021/10/08/hello-im-http-and-these-are-my-request-methods%f0%9f%91%8b%f0%9f%8f%bb/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.