Lesson 5 of 18
3. Client and Server

3.4 What do GET, POST, PUT, PATCH and DELETE mean?

3 min read+10 XP

Speaking HTTP

In the restaurant: There are only a few kinds of thing you say to a waiter: "show me the menu", "I'd like a dosa", "change my whole order to this", "just make the coffee cold", "cancel the dessert".

In the system: The method says what kind of action you want.

MethodMeaningBookstore example
GETRead somethingGET /books/42
POSTCreate something, or trigger an actionPOST /cart with {"book_id": "42"}
PUTReplace something completelyPUT /users/7/address with the full new address
PATCHChange part of somethingPATCH /users/7 with {"phone": "..."}
DELETERemove somethingDELETE /cart/items/3

Two properties interviewers love:

  • Safe: the method doesn't change anything on the server. GET (and HEAD, OPTIONS) are safe. Asking to see the menu doesn't cook anything.
  • Idempotent: doing it twice has the same effect as doing it once. GET, PUT and DELETE are idempotent: replacing your address with the same address twice leaves one address; deleting an item twice leaves it deleted. POST is not: sending "add book 42 to cart" twice can add it twice. PATCH isn't guaranteed to be idempotent either.

Why it matters: networks fail. When a request times out, the client often doesn't know whether it worked. Retrying an idempotent request is safe. Retrying a POST can double-order or double-charge, which is why payments need idempotency keys (Chapter 24).

Memory code: "GET looks, POST adds, PUT replaces, PATCH tweaks, DELETE removes." Safe = changes nothing. Idempotent = twice is the same as once.