Access the RESTCONF Datastores

Unlike REST implementations, RESTCONF offers deterministic URI strings and JSON formatting based on YANG data models. To retrieve data or configure a device using the RESTCONF interface, you must use the proper URI string to access the resource in question. Each YANG module defines a hierarchy of data that you can use to retrieve the URI and the exact parameters accepted by the JSON payload for RETCONF-based operations.

A RESTCONF URI is encoded from left to right, starting from the root to the target resource:

{+restconf}/data/<yang-module:container>/<leaf>[?<query_parameters]
  • {+restconf}/data is the root resource for the combined configuration and state data resources that can be accessed by a client, where {+restconf} indicates the root URL for the device.
  • <yang-module:container> is the base model container being used.
  • <leaf> is an individual element from within the container.
  • Some network devices may support options sent as <query_parameters> that impact returned results.

For example, to access the top-level interfaces resource within the openconfig-interfaces YANG model, the URL would be:

https://<ip>/rest/restconf/data/openconfig-interfaces:interfaces.

To access the interfaces data model and collect the data on interface=1 (port 1) on the device:

  1. Use the GET method to retrieve details of the specific interface:
    Sample client request
    GET  /rest/restconf/data/openconfig-interfaces:interfaces/interface=1
        HTTP/1.1
        Host: 10.68.13.192
  2. The server responds as follows:
    Sample server response
    {
      "openconfig-interfaces:interface": [
        {
          "config": {
            "description": "Port1", 
            "enabled": false, 
            "mtu": 1500, 
            "name": "1", 
            "type": "ethernetCsmacd"
          }, 
          "hold-time": {
            "config": {
              "down": 0, 
              "up": 0
            }, 
            "state": {
              "down": 0, 
              "up": 0
            }
          }, 
          "name": "1", 
          "openconfig-if-ethernet:ethernet": {
            "config": {
              "auto-negotiate": true, 
              "duplex-mode": "FULL", 
              "enable-flow-control": false, 
              "mac-address": "00:11:88:FE:AE:98", 
              "port-speed": "SPEED_1GB"
            }, 
            "openconfig-if-poe:poe": {
              "config": {
                "enabled": true
              }, 
              "state": {
                "enabled": true, 
                "power-class": 0, 
                "power-used": 0.0
              }
            }, 
            "openconfig-vlan:switched-vlan": {
              "config": {
                "access-vlan": 1, 
                "interface-mode": "ACCESS"
              }, 
              "state": {
                "access-vlan": 1, 
                "interface-mode": "ACCESS"
              }
            }, 
            "state": {
              "auto-negotiate": true, 
              "counters": {
                "in-8021q-frames": 0, 
                "in-crc-errors": 0, 
                "in-fragment-frames": 0, 
                "in-jabber-frames": 0, 
                "in-mac-control-frames": 0, 
                "in-mac-pause-frames": 0, 
                "in-oversize-frames": 0, 
                "out-8021q-frames": 0, 
                "out-mac-control-frames": 0, 
                "out-mac-pause-frames": 0
              }, 
              "duplex-mode": "FULL", 
              "effective-speed": 0, 
              "enable-flow-control": false, 
              "hw-mac-address": "00:11:88:FE:AE:98", 
              "mac-address": "00:11:88:FE:AE:98", 
              "negotiated-port-speed": "SPEED_UNKNOWN", 
              "port-speed": "SPEED_1GB"
            }
          }, 
          "state": {
            "admin-status": "DOWN", 
            "counters": {
              "in-broadcast-pkts": 0, 
              "in-discards": 0, 
              "in-errors": 0, 
              "in-multicast-pkts": 0, 
              "in-octets": 0, 
              "in-unicast-pkts": 0, 
              "in-unknown-protos": 0, 
              "last-clear": "2020-02-10T22:06:43Z", 
              "out-broadcast-pkts": 0, 
              "out-discards": 0, 
              "out-errors": 0, 
              "out-multicast-pkts": 0, 
              "out-octets": 0, 
              "out-unicast-pkts": 0
            }, 
            "description": "Port1", 
            "enabled": false, 
            "ifindex": 1001, 
            "last-change": 6500, 
            "mtu": 1500, 
            "name": "1", 
            "openconfig-platform-transceiver:physical-channel": [], 
            "openconfig-platform:hardware-port": "00:11:88:FE:AE:98", 
            "oper-status": "DOWN", 
            "type": "ethernetCsmacd"
          }, 
          "subinterfaces": {
            "subinterface": [
              {
                "config": {
                  "description": "", 
                  "enabled": true, 
                  "index": 1000004, 
                  "name": "Default"
                }, 
                "index": 1000004, 
                "state": {
                  "admin-status": "UP", 
                  "counters": {
                    "in-broadcast-pkts": 0, 
                    "in-discards": 0, 
                    "in-errors": 0, 
                    "in-multicast-pkts": 0, 
                    "in-octets": 0, 
                    "in-unicast-pkts": 0, 
                    "in-unknown-protos": 0, 
                    "out-broadcast-pkts": 0, 
                    "out-discards": 0, 
                    "out-errors": 0, 
                    "out-multicast-pkts": 0, 
                    "out-octets": 0, 
                    "out-unicast-pkts": 0
                  }, 
                  "description": "", 
                  "enabled": true, 
                  "ifindex": 1000004, 
                  "index": 1000004, 
                  "last-change": 7900, 
                  "name": "Default", 
                  "oper-status": "UP"
                }
              }
            ]
          }
        }
      ]
    }