Use PATCH to update data¶
When using the PUT
method, the client must supply all data in an entry to be
replaced, even when only changing one small part. This makes it difficult to
change, for example, the description of an ACL without sending the content of
the ACL back in the request.
The PATCH
method allows individual values to be replaced without requiring
all the data to be sent. With PATCH
, the client need only send the modified
values in a query, along with enough information to uniquely identify the entry.
For example, to update the description of the blockbadhosts
ACL using
PATCH
, the client must only include the name of the ACL and the new
description. It does not need to include the entire content of the ACL and its
rules as it would with a PUT
request.
Item |
Value |
---|---|
Request Type |
|
Content Type |
|
ACL Name |
|
ACL Description |
|
The command is formatted similarly to the PUT
request in the previous
example.
Warning
The Content-Type
header must be set when performing a write operation
such as PUT
or PATCH
. The value of the header must reflect the type
of data being sent. These examples use JSON, so the header is set to
application/yang-data+json
. When submitting XML, it would be
application/yang-data+xml
Command:
$ curl -f --cert ~/tnsr/tnsr-restconf-client.crt \
--key ~/tnsr/tnsr-restconf-client.key \
--cacert ~/tnsr/tnsr-restconf-CA.crt \
-H "Content-Type: application/yang-data+json" \
-X PATCH \
-d '{"netgate-acl:acl-list":[{"acl-name": "blockbadhosts","acl-description": "Block packets from bad hosts"}]}' \
https://tnsr.example.com/restconf/data/netgate-acl:acl-config/acl-table/acl-list=blockbadhosts/
Output: This command has no output when it works successfully.
Retrieve the contents of the ACL again to see that the new description is now present:
Command:
$ curl -f --cert ~/tnsr/tnsr-restconf-client.crt \
--key ~/tnsr/tnsr-restconf-client.key \
--cacert ~/tnsr/tnsr-restconf-CA.crt \
-X GET \
https://tnsr.example.com/restconf/data/netgate-acl:acl-config/acl-table/acl-list=blockbadhosts
Output:
{
"netgate-acl:acl-list": [
{
"acl-name": "blockbadhosts",
"acl-description": "Block packets from bad hosts",
"acl-rules": {
"acl-rule": [
{
"sequence": 1,
"action": "deny",
"ip-version": "ipv4",
"src-ip-prefix": "203.0.113.14/32"
},
{
"sequence": 2,
"action": "deny",
"ip-version": "ipv4",
"src-ip-prefix": "203.0.113.15/32"
},
{
"sequence": 10,
"action": "deny",
"ip-version": "ipv4",
"src-ip-prefix": "10.222.111.222/32"
},
{
"sequence": 555,
"action": "deny",
"ip-version": "ipv4",
"src-ip-prefix": "5.5.5.5/32"
},
{
"sequence": 5000,
"acl-rule-description": "Default Permit",
"action": "permit",
"ip-version": "ipv4"
}
]
}
}
]
}