Octet

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

PartMeaning
https://10.0.0.1The device, over HTTPS
/restconfAPI root
/dataThe datastore resource
/ietf-interfaces:interfacesModule name and top-level container
/interface=GigabitEthernet2List interface, entry whose key is GigabitEthernet2
/descriptionA leaf inside that entry
  • The root is found at /.well-known/host-meta; on most devices it is /restconf.
  • /restconf/data is the datastore, /restconf/operations lists RPCs.
  • Multiple keys are separated by commas. Reserved characters are percent-encoded: / becomes %2F.

Enable on IOS-XE

Cisco IOS
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
restconf

Read one interface

Shell
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
JSON
{
  "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.

Traps

  • Using application/json instead 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.