How does RESTCONF work? Show me a request and explain the URI.
Show the answer
Say this first
RESTCONF (RFC 8040) exposes YANG-modeled data over HTTPS with REST methods. The data tree lives under
/restconf/data; the URI is the model path, starting with module-name:node, with list keys after an
equals sign. Bodies use application/yang-data+json or application/yang-data+xml. GET reads, POST
creates, PUT creates or replaces, PATCH merges, DELETE removes. Each request is its own transaction:
there is no candidate, lock or confirmed commit like in NETCONF.
Go deeper
Anatomy of a URI
https://10.0.0.1/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2/description
| Part | Meaning |
|---|---|
https://10.0.0.1 | The device, over HTTPS |
/restconf | API root |
/data | The datastore resource |
/ietf-interfaces:interfaces | Module name and top-level container |
/interface=GigabitEthernet2 | List interface, entry whose key is GigabitEthernet2 |
/description | A leaf inside that entry |
- The root is found at
/.well-known/host-meta; on most devices it is/restconf. /restconf/datais the datastore,/restconf/operationslists RPCs.- Multiple keys are separated by commas. Reserved characters are percent-encoded:
/becomes%2F.
Enable on IOS-XE
username netops privilege 15 secret 0 S3cure.pass
aaa new-model
aaa authentication login default local
aaa authorization exec default local
ip http secure-server
restconfRead one interface
curl -s -k -u netops:S3cure.pass \
-H "Accept: application/yang-data+json" \
https://10.0.0.1/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet2{
"ietf-interfaces:interface": {
"name": "GigabitEthernet2",
"description": "to SW1 Gi1/0/48",
"type": "iana-if-type:ethernetCsmacd",
"enabled": true,
"ietf-ip:ipv4": {
"address": [
{
"ip": "10.1.12.1",
"netmask": "255.255.255.0"
}
]
},
"ietf-ip:ipv6": {
}
}
}Note the module: prefix on the top member and wherever a node comes from another module (ietf-ip:ipv4).
Useful query parameters
depth=2 limits how deep the reply goes, content=config or content=nonconfig picks config or state,
fields=name;description returns only some leafs, with-defaults controls default values.
They will ask next
How do you change several things atomically with RESTCONF?
Send one PATCH at a common parent that contains all the changes; the server applies one request as a unit. For edits spread across the tree, YANG Patch (RFC 8072,
application/yang-patch+json) lists several edits in one request. For real multi-step transactions with validate and confirmed commit, use NETCONF.What status codes does RESTCONF return for a successful PUT?
201 Created if the resource did not exist, 204 No Content if it replaced an existing one. PATCH returns 200 or 204 (most devices send 204), DELETE returns 204, and a POST that creates returns 201.
Traps
- Using
application/jsoninstead of the YANG media types. Some servers reject it or answer in a different format. - Leaving out the
module:prefix on the top-level JSON member, which gives a 400.