← All posts
Automation

REST API POST vs PATCH vs PUT: Which One Changes Network Config?

REST API POST vs PATCH vs PUT: Which One Changes Network Config?

Three Methods, One Confusion

POST, PUT, and PATCH all modify resources. That much is clear. What's not obvious until you've hit a few errors: they do very different things, and using the wrong one on a network device can wipe config you didn't mean to touch.

I've seen a PATCH request intended to update one field accidentally delete an entire interface config. It was actually a PUT. Easy mistake, bad outcome. Understanding the difference is not academic.

POST: Creating Something New

POST creates a new resource. Use it when the resource doesn't exist yet. Adding a new BGP neighbor, creating a new VLAN, adding a new static route.

The body of a POST contains the full definition of the new resource. For a new interface on a Cisco router via RESTCONF:

POST /restconf/data/ietf-interfaces:interfaces
Content-Type: application/yang-data+json { "ietf-interfaces:interface": { "name": "Loopback100", "type": "iana-if-type:softwareLoopback", "enabled": true }
}

If the resource already exists, you'll get a 409 Conflict. POST is not idempotent: run it twice and you'll get two resources (or an error on the second if the key is unique).

PUT: Replacing Everything

PUT replaces the entire resource with what you send. The body becomes the new state. Any field not in the body gets reset to default or deleted.

This is dangerous for partial updates. If you PUT a new interface config and forget to include the IP address, the IP address goes away. PUT is correct when you explicitly want to replace the full resource definition.

PUT /restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2
Content-Type: application/yang-data+json { "ietf-interfaces:interface": { "name": "GigabitEthernet2", "description": "New description", "type": "iana-if-type:ethernetCsmacd", "enabled": true, "ietf-ip:ipv4": { "address": [{"ip": "10.0.0.1", "prefix-length": 24}] } }
}

Notice the body includes the full interface definition. Leave out anything and it's gone. PUT is idempotent: run it twice with the same body and the state is the same both times.

PATCH: Updating Specific Fields

PATCH updates only the fields you send. Everything else stays exactly as it is. This is the right method for most day-to-day config changes.

PATCH /restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2
Content-Type: application/yang-data+json { "ietf-interfaces:interface": { "name": "GigabitEthernet2", "description": "Updated description only" }
}

That PATCH changes only the description. The IP address, admin state, and everything else are untouched. PATCH is idempotent too: same PATCH, same result.

DELETE: Removing a Resource

DELETE removes the resource at the URL. No body needed:

DELETE /restconf/data/ietf-interfaces:interfaces/interface=Loopback100

Success returns 204 No Content. Use DELETE for removing BGP neighbors, VLANs, static routes, or any resource you're deprovisioning.

The Idempotency Rule

GET, PUT, PATCH, and DELETE are idempotent: running them multiple times with the same input produces the same result. POST is not: it creates a new resource each time (or errors if the key already exists).

This matters for automation. If your script fails halfway and you re-run it, idempotent operations are safe to retry. POST is not. Design your automation around PATCH and PUT where possible.

RESTCONF Error Handling

The status code tells you what happened:

  • 204 No Content: PATCH/DELETE succeeded. No body in the response.

  • 400 Bad Request: Malformed JSON or invalid YANG data. Check your body structure against the YANG model.

  • 404 Not Found: The resource doesn't exist. Check the interface name or YANG path.

  • 409 Conflict: POST failed because the resource already exists.

Always check the response body on a 400. RESTCONF error responses include a JSON error object that tells you which field failed and why.

Quick Reference

MethodUse ForBody?Idempotent? GETRead config/stateNoYes POSTCreate new resourceYes (full)No PUTReplace full resourceYes (full)Yes PATCHUpdate specific fieldsYes (partial)Yes DELETERemove resourceNoYes

Practical Takeaway

Default to PATCH for config changes. Use POST only for creating new resources. Use PUT when you want to replace the full object intentionally, not just update one field. When in doubt, GET the resource first, modify the response, and PUT that back.

Watch the video

This is part of the Network Automation 101 series on YouTube.

Watch on YouTube →

Next in this series

Python requests: Your First GET to a Network Device API →

Comments (0)

Please sign in to comment.

  • Be the first to comment.