Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 82

Common API Characteristics (REST, NETCONF, RESTCONF)

Recommended resources

Hello! Welcome back to our module on Network Automation and Programmability.

In our last lesson, we contrasted traditional box-by-box network management with the modern controller-based approach. We established that the power of centralized controllers is unlocked through their Application Programming Interfaces (APIs), particularly the Northbound Interface (NBI), which allows software and automation tools to programmatically manage the network.

Today, we will dive into the heart of that programmatic control. This lesson addresses the learning outcome: Describe the characteristics of common APIs (REST, NETCONF, RESTCONF).

Given your experience with REST APIs and data formats like JSON, we'll begin with a quick review to place those concepts in a networking context. Then, we will explore two crucial IETF-standard protocols designed specifically for network automation—NETCONF and RESTCONF—and compare their characteristics to help you understand when and why you would choose one over the other.

The Need for a Common Language

Before we discuss the APIs themselves, we must address a foundational concept: structured versus unstructured data. As a network professional, your primary interface to a device has likely been the Command-Line Interface (CLI). While human-readable, CLI output is unstructured text. For a script or program, parsing this text is brittle and unreliable; a minor change in a software update (like adding a column to a show command) can break your automation.

Modern network automation requires structured data. This is data formatted in a predictable, hierarchical way that is easy for machines to parse and validate. This is where a data modeling language comes into play.

In modern networking, that language is YANG (Yet Another Next Generation). Think of YANG as a standardized way to create a "schema" or blueprint for a network device's configuration and operational data. It defines what data exists (e.g., an interface, a BGP neighbor), its type (e.g., string, integer), and how it's organized.

To get a better feel for what YANG is and why it's important, let's watch a short explanation from Hank Preston, a well-known voice in the network automation community.

YANG, NETCONF, RESTCONF Demos. Which Cisco devices are supported? (Part 1)

This video from David Bombal's channel introduces YANG data models. Pay attention to the analogy made between YANG models and SNMP MIBs—this is a very useful way to frame it, given your CCNA background.

Watch from 2:25 to 6:35 and then from 11:00 to 11:45. Focus on the core idea: YANG provides a consistent, standardized way to describe network components, solving the problem of inconsistent data representation across different platforms and vendors. Note the comparison to SNMP MIBs, which served a similar purpose in the past.

With YANG providing the common data models, NETCONF and RESTCONF act as the transport protocols to access and manipulate that data.


API Characteristics: REST, NETCONF, and RESTCONF

Now, let's explore the three key APIs mentioned in the learning outcome. We will look at their underlying transport, data encoding, and operational models.

1. REST APIs (A Quick Review in Context)

As you know, REST (Representational State Transfer) is not a protocol but an architectural style. When we talk about a "REST API," we generally mean an API that adheres to REST principles and uses HTTP/S for transport.

In the networking world, you'll encounter two main flavors of REST APIs:

  • Native REST APIs: These are vendor-specific APIs. A good example is Cisco's NX-API REST for the Nexus platform. While it's a RESTful API using HTTP/S and returning JSON/XML, the structure of the API calls (the URIs) and the data models it uses are specific to that platform (it uses the Management Information Tree or MIT, not YANG directly).
  • Standards-based RESTful APIs: This is where RESTCONF fits in, which we will detail shortly.

Your existing knowledge of HTTP methods (GET, POST, PUT, DELETE), status codes, and JSON/XML is directly applicable here. The key difference in the networking context is what the "resource" is—instead of a user profile on a website, it's a router interface, a BGP configuration, or a table of ARP entries.

2. NETCONF (Network Configuration Protocol)

NETCONF is a robust, IETF-standard protocol (RFC 6241) built from the ground up specifically for installing, manipulating, and deleting the configuration of network devices. It was designed to overcome the limitations of older methods like SNMP and CLI scraping.

Let's watch a brief overview of the NETCONF model.

Getting Started with NETCONF

This video from Kevin Wallace Training provides a clear introduction to the NETCONF client-server model and its core components.

Watch from 2:39 to 4:50. Focus on understanding the manager-agent relationship, the use of YANG for data modeling, XML for encoding, and SSH for secure transport.

Based on the video and its specification, here are the key characteristics of NETCONF:

  • Transport: Uses SSH as its transport protocol, typically on port 830. This makes it familiar and secure from a network administrator's perspective.
  • Encoding: Strictly uses XML (Extensible Markup Language) for all messages.
  • Operations: It has a well-defined set of RPC-style operations. The most common are:
    • <get-config>: Retrieve all or part of a specified configuration datastore.
    • <edit-config>: Modify a configuration datastore.
    • <get>: Retrieve running configuration and device state information.
    • <copy-config>: Copy an entire configuration datastore to another.
    • <delete-config>: Delete a configuration datastore.
  • Key Feature - Datastores: NETCONF formally defines the concept of separate configuration datastores, such as running, candidate, and startup. This allows you to make changes to a candidate configuration, validate them, and then commit them to the running configuration as a single transaction.
  • Key Feature - Transactions: NETCONF supports atomic transactions. When you commit a set of changes, either all of them succeed, or none of them do. The system automatically rolls back if an error occurs. This is a massive advantage for reliability over executing CLI commands one by one.

3. RESTCONF

While NETCONF is powerful, its reliance on XML and a specific RPC model can be a barrier for web and application developers who are more accustomed to RESTful interfaces. RESTCONF (RFC 8040) was created to bridge this gap. It provides a REST-like API to access the same YANG-defined data that NETCONF uses.

RESTCONF Operation Diagram
This diagram illustrates the RESTCONF architecture. A client communicates via HTTP/S with the RESTCONF server on a network device. The server translates these requests into operations on the YANG datastore, which in turn configures the device.

Key characteristics of RESTCONF:

  • Transport: Uses HTTPS, typically on port 443. This makes it firewall-friendly and easy to use with common programming libraries.
  • Encoding: Supports both XML and JSON, giving the client flexibility to choose their preferred format using HTTP Accept headers.
  • Operations: It maps standard HTTP methods to operations on the YANG data models. For example:
    • GET: Corresponds to retrieving data (<get>).
    • POST: Used to create resources.
    • PUT: Used to replace resources.
    • PATCH: Used to modify a resource.
    • DELETE: Used to delete a resource.
  • Key Feature - Accessibility: By using standard HTTP/S and supporting JSON, RESTCONF makes network programmability accessible to a much broader range of developers.

It's crucial to understand that RESTCONF is not just any REST API. It is a standard that defines how HTTP methods and URIs are mapped specifically to YANG models.

Introduction to Programmability – Part 3

This Cisco blog post contains a vital section that contrasts a standard-based API like RESTCONF with a native, vendor-specific API like NX-API REST.

Please read the section titled 'Standards-based vs. Native RESTful APIs: RESTCONF & NX-API REST'. This will clarify the distinction between a general RESTful API and the specific RESTCONF standard.


Head-to-Head Comparison

To consolidate these concepts, let's turn to a very useful comparison table from a Cisco Live presentation. This document provides a side-by-side analysis that is perfect for both deep understanding and exam review.

[PDF] Modern approaches for IOS XE network device management on Cat9K

This PDF from a Cisco Live session contains an excellent table comparing NETCONF, RESTCONF, and another protocol, gNMI. We will focus on the first two.

First, study the table on slide 28, titled 'Model Driven Programmability Interface Comparison'. Pay close attention to the rows for Default Port, Operations, Encoding, Transport, Benefits/Pros, and Caveats/Cons for NETCONF and RESTCONF. Then, read the descriptions on slide 31 ('About NETCONF') and slide 32 ('About RESTCONF') to reinforce these points.

Here is a summary of the key trade-offs from that resource:

Characteristic NETCONF RESTCONF
Standard IETF RFC 6241 IETF RFC 8040
Transport SSH HTTPS
Default Port 830 443
Encoding XML JSON or XML
Paradigm RPC (Remote Procedure Call) RESTful (Mapping HTTP verbs to data)
Strengths Mature, transactional, supports configuration datastores (candidate), locking, rollback. High reliability for complex changes. Web-friendly, easy for developers to adopt, flexible encoding (JSON). Lower barrier to entry.
Weaknesses Steeper learning curve, XML can be verbose and difficult to work with manually. Lacks some of the advanced transactional features of NETCONF (e.g., no candidate datastore).
Test your understanding!

You are designing an automation workflow with two distinct requirements:

  1. Requirement A: A new web-based portal needs to be created for the helpdesk team. The portal must display the real-time operational status and statistics of switch interfaces in a simple, readable format. The development team has extensive experience with JavaScript and web frameworks but no prior network automation knowledge.

  2. Requirement B: A critical maintenance window requires you to update the QoS policies on 50 core routers. The change involves multiple interdependent commands. It is absolutely essential that if any part of the update fails on a router, the entire configuration change for that router is discarded, leaving it in its original state.

Which API—NETCONF or RESTCONF—would be the most appropriate choice for each requirement, and why?

Show answer
  • Requirement A (Helpdesk Portal): RESTCONF is the ideal choice.

    • Why: The web development team is already familiar with REST principles and likely prefers to work with JSON, which RESTCONF supports. Using HTTPS (port 443) is standard for web traffic and requires no special firewall considerations. The simplicity of a GET request to retrieve interface data is a much lower barrier to entry than constructing a NETCONF RPC call.
  • Requirement B (Critical QoS Update): NETCONF is the superior and safer choice.

    • Why: The key here is the need for a reliable, all-or-nothing change. NETCONF's support for atomic transactions is precisely what is needed. You can send the entire series of changes as a single <edit-config> operation. If any part of it is invalid, the device will reject the entire transaction, ensuring the router's configuration remains consistent and stable. Trying to replicate this with a series of RESTCONF PATCH or PUT calls would be far more complex and risky.

Conclusion

In this lesson, we've dissected the characteristics of the three main types of APIs you'll encounter in network automation. We have moved from the general principles of REST to the network-specific, standardized protocols of NETCONF and RESTCONF.

Key Takeaways:

  • Modern network automation is built on structured data, with YANG serving as the standard modeling language.
  • REST APIs in networking can be native (vendor-specific) or standards-based.
  • NETCONF is a powerful, RPC-based protocol over SSH using XML. Its main strengths are its robust transactional capabilities and support for multiple configuration datastores.
  • RESTCONF provides a RESTful interface to YANG models over HTTPS, supporting both JSON and XML. It lowers the barrier to entry for developers and integrates easily with web-based tools.
  • The choice between NETCONF and RESTCONF depends on the use case: NETCONF for reliability and complex configuration changes, RESTCONF for accessibility and simple data retrieval/modification.

Preview of the Next Lesson:
Now that we understand the APIs that transport the data, our next lesson will focus on the data itself. The learning outcome will be to "interpret JSON encoded data returned from a REST API call." Since you're already familiar with the format, we will focus on practical examples from network devices, understanding how to navigate the nested structures to extract the specific information you need for your automation scripts.