PUT vs PATCH, and what does idempotent mean?
Try code in the playgroundUnderstand the concept
PUT is defined around creating or replacing the state of a target resource, while PATCH applies a described partial change. Idempotency means repeating an identical operation has the same intended server-side effect as doing it once. It does not require every repeated response to contain the same status or body.
Important ideas
-
PUT replaces the target representation; PATCH applies a partial change.
-
Idempotent means repeating the same request has the same intended effect.
-
PUT and DELETE are idempotent by semantics; PATCH depends on the operation.
-
“Set quantity to 3” can be idempotent; “increase quantity by 3” generally is not without a deduplication mechanism.
Work through the example
PUT /profiles/42with the same profile representation leaves the same intended state after repetition.PATCH /counters/42with “increment by 1” changes the state again on each attempt unless an idempotency key is enforced.- A repeated request can have a different response while still being idempotent.
Can you explain it without the notes?
PUT vs PATCH, and what does idempotent mean?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
PUT is defined around creating or replacing the state of a target resource, while PATCH applies a described partial change. Idempotency means repeating an identical operation has the same intended server-side effect as doing it once. It does not require every repeated response to contain the same status or body.
Turn this concept into a clear answer.
- A repeated DELETE can return 404 after an initial success while remaining idempotent because the resource stays deleted.
Adapted from 02_NODE_EXPRESS_HTTP.md · “PUT vs PATCH, and what does idempotent mean?”. Examples are study fragments; framework behavior can depend on your version.