When the Wrong Method Causes Real Damage
Here's a situation I've seen more than once. Someone writes a script to update the description on a router interface. They test it on one device, it works. They run it on fifty devices. Half the interfaces lose their IP addresses.
The script used PUT instead of PATCH. PUT replaced the entire interface config with just the description field. No IP. No mask. Gone.
This post walks through the same change using POST, PUT, and PATCH side by side in Postman, so the difference is impossible to miss.
Setup: Same Request, Three Methods
Use the Cisco DevNet sandbox (sandbox-iosxe-latest-1.cisco.com). Start by getting the current state of GigabitEthernet2 so you can compare before and after:
GET https://sandbox-iosxe-latest-1.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2
Accept: application/yang-data+json
Authorization: Basic YWRtaW46QzFzY28xMjM0NQ==Save the response. That's your before state.
POST: Creating a New Interface
POST to the interfaces collection (not to a specific interface URL) to create Loopback99:
POST https://sandbox-iosxe-latest-1.cisco.com/restconf/data/ietf-interfaces:interfaces
Content-Type: application/yang-data+json { "ietf-interfaces:interface": { "name": "Loopback99", "type": "iana-if-type:softwareLoopback", "description": "Test loopback", "enabled": true }
}Success: 201 Created. Run it again: 409 Conflict (interface already exists). POST is not idempotent.
Now GET the loopback to confirm it exists. Then DELETE it to clean up before the next test:
DELETE https://sandbox-iosxe-latest-1.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=Loopback99PUT: The Dangerous One
PUT replaces the entire resource. Try updating just the description of GigabitEthernet2 with PUT:
PUT https://sandbox-iosxe-latest-1.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2
Content-Type: application/yang-data+json { "ietf-interfaces:interface": { "name": "GigabitEthernet2", "description": "Updated via PUT" }
}Success: 204 No Content. Now GET the interface. The description changed. But what else changed? Run the before-and-after GET comparison. Depending on the device, PUT may have reset or removed other fields that weren't in your body.
This is exactly the scenario that wipes IP addresses. PUT is correct when you have the full resource definition and you want to replace it entirely. Never use it for partial updates.
PATCH: Safe Partial Update
PATCH sends only what you want to change:
PATCH https://sandbox-iosxe-latest-1.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2
Content-Type: application/yang-data+json { "ietf-interfaces:interface": { "name": "GigabitEthernet2", "description": "Updated via PATCH" }
}Success: 204 No Content. GET the interface. Description changed. Everything else is exactly as it was before. That's the difference.
Reading the Diff in Postman
Postman doesn't have a built-in diff view, but you can approximate it. Save the before-GET response as a Postman example. After each PUT or PATCH, run the GET again and manually compare. For a real diff workflow, export both responses as JSON and run them through a diff tool.
A better approach: in the Postman Tests tab (the tab after "Body" in a request), write a test that checks the fields you care about:
pm.test("Description was updated", function() { var body = pm.response.json(); var iface = body["ietf-interfaces:interface"]; pm.expect(iface.description).to.equal("Updated via PATCH");
}); pm.test("IP address still present", function() { var body = pm.response.json(); var iface = body["ietf-interfaces:interface"]; pm.expect(iface["ietf-ip:ipv4"]).to.exist;
});When PUT Is the Right Choice
PUT is correct when you want to define the complete, authoritative state of a resource. If you're applying a full interface configuration from a source of truth (a YAML file or NetBox), PUT what you want the interface to look like. Any drift gets corrected because PUT replaces everything.
The pattern: GET the current state, modify the full object, PUT it back. Never PUT a partial body unless you explicitly want to clear the missing fields.
Saving as Runnable API Documentation
Once you have POST, PUT, PATCH, and DELETE requests working in a Postman collection, that collection is documentation. Export it as a JSON file and check it into your repo. Any team member can import it and run the same calls against any environment. Add Postman environments for dev, staging, and production, and you have a testable API reference that actually works.
Practical Takeaway
Default to PATCH. Only use PUT when you have the full resource definition and you mean to replace everything. Test every config-change method against a non-production device first and always run a GET before and after to confirm exactly what changed.
Watch the video
This is part of the Network Automation 101 series on YouTube.
Comments (0)
Please sign in to comment.