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
| Method | CRUD | Safe | Idempotent | Typical success |
|---|---|---|---|---|
| GET | Read | Yes | Yes | 200 |
| POST | Create, or run an action | No | No | 201 (created) or 200 |
| PUT | Create or replace | No | Yes | 201 (created) or 200/204 (replaced) |
| PATCH | Partial update | No | Not guaranteed | 200 or 204 |
| DELETE | Delete | No | Yes | 204 or 200 |
| HEAD | Read headers only | Yes | Yes | 200 |
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.
They will ask next
How would you make a POST safe to retry?
Check first (GET by a natural key such as name) and create only if missing, or use an API that supports an idempotency key or a client-chosen ID. Some APIs let you PUT to a known URI instead.
Which methods does RESTCONF use for what?
GET to read, POST to create a child resource or invoke an RPC, PUT to create or replace, PATCH to merge, DELETE to remove. POST of something that already exists returns 409 Conflict.
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.