You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
RESTCONF (RFC 8040) is an HTTP-based protocol for accessing network configuration and state data defined by YANG models. It brings the simplicity and familiarity of REST APIs to network management. Beyond RESTCONF, many network vendors and controllers offer their own REST APIs for automation.
RESTCONF is essentially NETCONF over HTTP. It uses the same YANG data models but replaces XML-over-SSH with HTTP methods and JSON or XML encoding:
| Feature | NETCONF | RESTCONF |
|---|---|---|
| Transport | SSH (port 830) | HTTPS (port 443) |
| Encoding | XML | JSON or XML |
| Operations | RPC-based | HTTP methods (GET, POST, PUT, PATCH, DELETE) |
| URL structure | XPath / subtree filters | RESTful resource URIs |
| Tooling | ncclient (Python) | Any HTTP client (curl, requests, Postman) |
| Ease of use | Medium | High — familiar to web developers |
| HTTP Method | RESTCONF Operation | Description |
|---|---|---|
| GET | Read | Retrieve configuration or operational data |
| POST | Create | Create a new resource |
| PUT | Create or Replace | Create or completely replace a resource |
| PATCH | Update (Merge) | Partially update a resource |
| DELETE | Delete | Remove a resource |
The RESTCONF URL follows the YANG model hierarchy:
https://<device>/restconf/data/<module>:<container>/<list>=<key>/<leaf>
| URL | Description |
|---|---|
/restconf/data/ietf-interfaces:interfaces | All interfaces |
/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet1 | A specific interface |
/restconf/data/Cisco-IOS-XE-native:native/hostname | Device hostname |
/restconf/data/openconfig-network-instance:network-instances | Routing instances |
curl -k -u admin:secret \
-H "Accept: application/yang-data+json" \
https://192.168.1.1/restconf/data/ietf-interfaces:interfaces
curl -k -u admin:secret \
-H "Accept: application/yang-data+json" \
https://192.168.1.1/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet1
curl -k -u admin:secret \
-X PUT \
-H "Content-Type: application/yang-data+json" \
-d '{
"ietf-interfaces:interface": {
"name": "Loopback99",
"description": "Created via RESTCONF",
"type": "iana-if-type:softwareLoopback",
"enabled": true
}
}' \
https://192.168.1.1/restconf/data/ietf-interfaces:interfaces/interface=Loopback99
curl -k -u admin:secret \
-X PATCH \
-H "Content-Type: application/yang-data+json" \
-d '{
"ietf-interfaces:interface": {
"name": "Loopback99",
"description": "Updated via RESTCONF"
}
}' \
https://192.168.1.1/restconf/data/ietf-interfaces:interfaces/interface=Loopback99
curl -k -u admin:secret \
-X DELETE \
https://192.168.1.1/restconf/data/ietf-interfaces:interfaces/interface=Loopback99
import requests
import json
# Disable SSL warnings (lab only)
requests.packages.urllib3.disable_warnings()
BASE_URL = "https://192.168.1.1/restconf"
HEADERS = {
"Accept": "application/yang-data+json",
"Content-Type": "application/yang-data+json",
}
AUTH = ("admin", "secret")
def get_interfaces():
"""Retrieve all interfaces via RESTCONF."""
url = f"{BASE_URL}/data/ietf-interfaces:interfaces"
response = requests.get(url, headers=HEADERS, auth=AUTH, verify=False)
response.raise_for_status()
return response.json()
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.