RESTCONF 101: Introduction to RESTCONF

In this Learning Lab, you will learn the basics of the RESTCONF protocol and how to consume a RESTCONF API using Postman.

Objective

Completion Time: 30 minutes

  • Understand the benefits of RESTCONF
  • Understand the basics of the RESTCONF protocol
  • Understand the basics of consuming RESTCONF APIs
  • Use Postman to make RESTCONF API calls

Prerequisites

You will want to make sure you have gone through the Coding 101 lab if you are unfamiliar with retrieving results from a RESTful service. Also, this lab includes steps in the How to Setup Your Computer section to setup your development environment if needed.

In this lab, we are going to use Postman to make RESTCONF API calls.

If you are on a DevNet Zone station, Postman is already installed and can be launched either from the Google App Launcher or from chrome by clicking here and hitting Launch App.

Access to a Device that Supports RESTCONF APIs

Step 1. Understanding the benefits of RESTCONF

RESTCONF ensures consistency of a REST-like interface across devices from different vendors or devices running different operating systems. RESTCONF helps simplify network automation. When it comes to automating networks, there are a number of challenges such as those listed below.

  1. Inconsistencies across platforms
    • Networking devices from different vendors or running different operating systems often have different programmatic interfaces
  2. Unstructured data
    • Although the command-line interface (CLI) is the most well-known interface into network devices, the data from CLI is unstructured and cumbersome to operate programmatically

To see an example of these issues in action, take a look at the following Python code example which parses a simple network configuration.

#!/usr/bin/python

import re


def main():
    """Open a file called static-routes.txt and print each line that matches a REGEX for a static route."""
    with open('static-routes.txt', 'r') as static_routes:
        for route in static_routes:
            if re.match('^ip route (\d{1,3}\.){3}\d{1,3} '
                        '(\d{1,3}\.){3}\d{1,3} (\d{1,3}\.){3}\d{1,3}
, route): print(route.rstrip()) if __name__ == '__main__': main()

The file static-routes.txt contains CLI configuration for two static routes (shown below). An engineer may want to audit the configurations of all network devices and retrieve this configuration data. Running the Python script above should print these static routes.

ip route 192.168.1.0 255.255.255.0 10.0.0.1
ip route 192.168.2.0 255.255.255.0 10.0.0.2

Although we should expect to see both lines of the file printed to the screen showing both of our static routes, the output below illustrates that we are running into an issue since only one route is printed.

ubuntu$ python screen_scraping.py
ip route 192.168.1.0 255.255.255.0 10.0.0.1

The example above illustrates some of the challenges when parsing legacy CLI to automate networks. First, CLIs may differ based on the used platform, forcing users to develop custom code or plugins to account for every vendor or network operating system. Second, in the example above, the file in question has additional trailing white-space on the last line. The CLI of the network OS provides unstructured data which creates additional work for the programmer to ensure proper parsing of any relevant data.

RESTCONF overcomes these issues by using structured data (XML or JSON) and YANG to model configuration syntax and operational state to ensure consistency of a REST-like API across different platforms. Developers or engineers accustomed to a REST-like interface may quickly start using a RESTCONF API to programmatically access network devices.

In the next part of the exercise, we shall provide an overview of the relationship between RESTCONF, SNMP, NETCONF, and REST.