Node.jsInterview preparation
Foundation·Concept·2 min read

PUT vs PATCH, and what does idempotent mean?

Practice this question

Definition:

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.

Key points:

  • 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.

Example:

  • PUT /profiles/42 with the same profile representation leaves the same intended state after repetition.
  • PATCH /counters/42 with “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.

Interview point:

  • 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?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.