HTTP Methods
HTTP Methods (also called "Verbs") tell the server exactly what you want to do with a resource. Using the right method is critical for building predictable web apps.
Step 1 of 4
Read a resource. No side effects.
Create a new resource.
Replace a resource entirely.
Remove a resource forever.
Worked example
Request
POST /users HTTP/1.1
Content-Type: application/json
{"name": "Alice"}Notice that POST has a "Body" (the JSON data). GET requests do not have bodies.
- •GET
- •POST
- •PUT
- •DELETE
Primary Methods
There are several methods, but these four handle 99% of web traffic:
- GET — Fetch data. It should NEVER change anything on the server. It's like reading a book.
- POST — Create data. Used when submitting forms or signing up. It's like writing a new page in a book.
- PUT — Update data. Replaces an existing resource entirely. It's like replacing a whole page.
- DELETE — Remove data. Deletes the resource from the server. It's like ripping a page out.
Safe vs Unsafe Methods
Methods like GET and HEAD are "Safe" because they don't modify anything. POST, PUT, and DELETE are "Unsafe" because they change the state of the server.
Idempotency (Master Concept)
An operation is "Idempotent" if performing it multiple times has the same result as performing it once. GET, PUT, and DELETE are idempotent. POST is NOT idempotent because sending it twice might create two users!
Study kit
Module 3 of 18
Beginner · 2 min · 0 of 18 complete
Module status
Not completed yet
Notessaved locally+
Notes stay in this browser. They are not uploaded.
Suggest an editLearning graph
Prerequisites
Discussion
Loading discussion…
Sign in to ask a question.