Cisco Platforms and Development · Topic 5 of 8

Device Level APIs for IOS XE and NX-OS

Learn the programmable interfaces on Cisco IOS XE and NX-OS devices, including NETCONF, RESTCONF, gNMI, NX-API CLI and NX-API REST, and how to enable them.

  • 5 min
In a nutshell
  • Device level APIs manage one device without a controller.
  • IOS XE supports NETCONF, RESTCONF and gNMI, enabled with netconf-yang and restconf.
  • RESTCONF on IOS XE also needs ip http secure-server.

What it is

Device level APIs are programmable interfaces that run on a single switch or router, so you can manage that box without going through a controller.

Both IOS XE and NX-OS offer them. Beside the traditional CLI and SNMP, they provide model driven interfaces and REST style interfaces.

You need to know which interface each platform offers, how to switch it on, and what each one is good at.

ScriptPython or a toolAPI requestDeviceIOS XE or NX OSstructured dataScriptparses JSON or XML

How it works

Each platform has its own set of interfaces, and some of them must be enabled first.

Interfaces on IOS XE

InterfaceWhat it is
CLI over SSHThe traditional text interface, which scripts can drive
SNMPOlder monitoring protocol
NETCONFXML based, model driven management over SSH, on port 830 by default
RESTCONFREST style access to the same YANG models, using HTTPS with JSON or XML
gNMIgRPC based interface, often used for streaming telemetry
On box PythonPython scripts run on the device in the guest shell

NETCONF and RESTCONF use the YANG data models, which the next page covers.

Enabling NETCONF and RESTCONF on IOS XE

Router(config)# netconf-yang
Router(config)# restconf
Router(config)# ip http secure-server
Router(config)# username admin privilege 15 secret PASSWORD

The netconf-yang command turns on the NETCONF server. The restconf command turns on RESTCONF, and it needs the HTTPS server, which ip http secure-server provides. The account needs the right privilege level.

A RESTCONF request to IOS XE

GET /restconf/data/ietf-interfaces:interfaces HTTP/1.1
Host: ROUTER_ADDRESS
Accept: application/yang-data+json
Authorization: Basic BASE64_OF_USER_AND_PASSWORD

The path starts with /restconf/data/, followed by a module name, a colon and a container name. The media type application/yang-data+json asks for JSON in the YANG data form.

Interfaces on NX-OS

InterfaceWhat it is
NX-API CLISends CLI commands over HTTP or HTTPS and returns structured output
NX-API RESTREST access to the object model of the switch, called the DME
NETCONF and RESTCONFModel driven interfaces, supported on many platforms and releases
gRPCUsed for telemetry and configuration on supported releases
On box Python and BashScripting on the switch itself

Enabling NX-API

Switch(config)# feature nxapi
Switch# show nxapi

The feature nxapi command turns on the web server for NX-API. show nxapi shows its state and the ports it uses. NX-OS also has a developer sandbox page in the browser, where you can try a command and copy the generated request.

NX-API CLI

NX-API CLI takes ordinary show and configuration commands and returns the result as JSON or XML, so you do not have to parse screen text. Requests go to the /ins path.

{
  "ins_api": {
    "version": "1.0",
    "type": "cli_show",
    "chunk": "0",
    "sid": "1",
    "input": "show version",
    "output_format": "json"
  }
}

The type field says whether the command is a show command or a configuration command. The input field holds the CLI command.

A Python script sends it with requests.

import requests

response = requests.post(
    BASE_URL + "/ins",
    json=payload,
    headers={"content-type": "application/json"},
    auth=("admin", PASSWORD),
    verify=False,
)
print(response.json())

NX-API REST and the object model

NX-API REST exposes the NX-OS data management engine, or DME. Everything on the switch is a managed object in a tree, and you read or change an object by its path.

GET /api/mo/sys/intf/phys-[eth1/1].json

The path /api/mo/ addresses one managed object and /api/class/ queries all objects of a class. Interface names appear in the path in a special bracketed form.

Choosing an interface

  • Quick scripts that already use CLI commands: NX-API CLI, or CLI over SSH.
  • Structured, model based work on either platform: NETCONF or RESTCONF.
  • Streaming telemetry from the device: gNMI or gRPC.
  • Logic that must run on the box itself: on box Python.
Exam tip

On IOS XE the REST style interface is RESTCONF, which uses YANG paths. On NX-OS, the REST style interface that is best known is NX-API REST, which uses the object model.

What to remember for the exam

Six facts cover this topic.

  • Device level APIs manage one device without a controller.
  • IOS XE supports NETCONF, RESTCONF and gNMI, enabled with netconf-yang and restconf.
  • RESTCONF on IOS XE also needs ip http secure-server.
  • NETCONF uses port 830 by default.
  • NX-OS enables its web API with feature nxapi.
  • NX-API CLI sends commands to /ins, and NX-API REST addresses objects under /api/mo/.

Common mistakes

Four mistakes are typical.

Forgetting to enable the feature. The API does not answer until restconf, netconf-yang or feature nxapi is set.

Mixing up NX-API CLI and REST. One carries CLI commands, and the other works on managed objects.

Skipping the HTTPS server on IOS XE. RESTCONF needs it.

Parsing screen text when structured data exists. The device can return JSON or XML, which is safer.

Watch out

A lab habit of verify=False skips certificate checks. Do not carry it into production.

Check yourself

Work through these three questions.

  • Which commands enable NETCONF and RESTCONF on IOS XE?

    netconf-yang and restconf, plus ip http secure-server for RESTCONF.

  • Which command enables NX-API on NX-OS?

    feature nxapi.

  • How does NX-API CLI differ from NX-API REST?

    NX-API CLI carries CLI commands to /ins, while NX-API REST reads and changes managed objects under /api/mo/.

Topic 5 of 8 in Cisco Platforms and Development

Test yourself on Cisco Platforms and Development

The full Cisco CCNA 200-901 DEVASC question bank has 808 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.