SteelReed

Search

Search posts, questions…

Web & REST APIQuestion 8 / 25

Junior

What is the difference between safe and idempotent? Name a method that is idempotent but not safe?

Short answer

Safe: the request does not change server state on the client's behalf. Idempotent: sending it once or N times leaves the same final state; PUT and DELETE are idempotent but not safe, POST is neither.

Method Safe Idempotent
GET, HEAD, OPTIONS Yes Yes
PUT, DELETE No Yes
POST No No
PATCH No Depends on design

3 points to say:

  1. After a timeout the client doesn't know whether the server processed it; idempotent methods let clients and proxies retry automatically, POST needs an idempotency key.
  2. Idempotency is about state, not the response: a second DELETE may return 404.
  3. Safe requests still get logged and counted; and code can break idempotency (a PUT that creates a new id or sends an email each time).

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.