Octet

Walk me through the HTTP methods. Which ones are idempotent, and why does that matter for automation?

Show the answer

Say this first

GET reads, POST creates or triggers an action, PUT creates or replaces the whole resource at a URI, PATCH changes part of it, DELETE removes it. GET, PUT and DELETE are idempotent: sending the same request twice leaves the server in the same state as sending it once. POST is not, and PATCH is not guaranteed to be. That matters because a script that times out can safely retry an idempotent call.

Go deeper

The table

MethodCRUDSafeIdempotentTypical success
GETReadYesYes200
POSTCreate, or run an actionNoNo201 (created) or 200
PUTCreate or replaceNoYes201 (created) or 200/204 (replaced)
PATCHPartial updateNoNot guaranteed200 or 204
DELETEDeleteNoYes204 or 200
HEADRead headers onlyYesYes200

Safe means it does not change state. Idempotent means repeating it has the same effect on the server as doing it once. The response can differ: a second DELETE may return 404, but the resource is still gone, so DELETE is idempotent.

The network trap with PUT

PUT replaces the target. If you PUT an interface with only a new description, a RESTCONF server replaces that whole interface entry with what you sent, and leaves you without the IP address you left out. Use PATCH (merge) to change one field.

Why automation cares

Networks are unreliable. If a POST times out you do not know whether the object was created, and a retry may create a duplicate. With PUT you can retry until it succeeds. The same idea is why Ansible modules are written to be idempotent.

Traps

  • Saying DELETE is not idempotent because the second call returns 404. Idempotency is about server state.
  • Using PUT for a one-field change and silently wiping the rest of the object.
How did you do?Book 9.1 Traditional Applications