← All posts
Automation

What is a REST API and Why Every Network Engineer Should Care

What is a REST API and Why Every Network Engineer Should Care

The Old World: CLI and Why It Breaks at Scale

For years, network engineers have configured devices the same way: SSH in, type commands, SSH out. It works fine for one device or ten. At a hundred devices, it starts to hurt. At five hundred, it's unmanageable.

The problem isn't just speed. It's consistency. Every engineer has a slightly different style. Configs drift. Someone forgets to make the same change on the standby device. You can't easily audit what changed, when, or why. CLI is designed for humans, not for programs.

REST APIs change that. Instead of a human typing commands, your code sends structured HTTP requests and gets structured JSON back. The same change, applied the same way, every time.

What REST Actually Means

REST stands for Representational State Transfer. The name is academic and not especially useful. What matters: REST is a style of web API that uses HTTP as the transport and treats everything on the device (interfaces, routes, BGP neighbors, VLANs) as a "resource" with a URL.

REST is stateless. Each request carries everything the server needs to handle it. There's no session, no "you logged in earlier," no connection state. Send the right request with the right credentials and you get back the right data.

Responses come back as JSON (or sometimes XML). That means you can parse them directly in Python, store them in a database, diff them, or feed them into another system. No screen-scraping, no regex on CLI output.

The Five HTTP Methods Every Network Engineer Needs

REST uses standard HTTP methods. Each one maps to an operation on a network device resource:

  • GET: Read the current state. Interface config, routing table, BGP summary. No changes made.

  • POST: Create a new resource. Add a new BGP neighbor, create a VLAN, add a route.

  • PUT: Replace a resource entirely. The body you send becomes the new state. Anything not in the body gets deleted. Use this carefully.

  • PATCH: Update specific fields only. The body contains only what changes. Everything else stays. This is what you want for most config changes.

  • DELETE: Remove a resource. Delete a BGP neighbor, remove a VLAN, withdraw a route.

The most common operations in day-to-day automation: GET to read, PATCH to update. POST and DELETE come up for provisioning and deprovisioning. PUT is rare and risky if you're not careful.

HTTP Status Codes You'll See

REST APIs communicate success and failure through HTTP status codes. These aren't optional reading , they tell you exactly what happened to your request:

  • 200 OK: Success. The GET returned data, the PATCH worked.

  • 201 Created: A POST succeeded and created a new resource.

  • 204 No Content: Success, but nothing to return. PATCH and DELETE usually return this.

  • 400 Bad Request: Your request body was malformed. Check the JSON syntax and the YANG model.

  • 401 Unauthorized: Bad credentials. Check username/password or token.

  • 404 Not Found: The URL path doesn't match a resource. Check spelling and the interface name.

  • 409 Conflict: The resource already exists and you tried to POST it again.

  • 500 Server Error: Something failed on the device. Check device logs.

Reading a Network API URL

REST API URLs in network devices follow a predictable pattern. Here's a RESTCONF URL for a Cisco router interface:

https://192.168.1.1/restconf/data/ietf-interfaces:interfaces/interface=GigabitEthernet1

Breaking that down: /restconf/data/ is the RESTCONF base path. ietf-interfaces:interfaces is the YANG module and container. interface=GigabitEthernet1 is the list key (the specific interface you want).

Once you read URLs this way, every network API makes sense. The path tells you exactly what resource you're touching.

RESTCONF: The Standard for Network Device REST APIs

RESTCONF (RFC 8040) is the IETF standard that maps REST operations onto YANG data models. If a device supports NETCONF and YANG, it usually supports RESTCONF too. Cisco IOS-XE, IOS-XR, NX-OS, Arista EOS, and Junos all support it.

RESTCONF sits on top of HTTP. You authenticate the same way (basic auth or token), send JSON or XML, and get JSON or XML back. The URL structure follows the YANG model tree.

This matters because RESTCONF is vendor-neutral (in theory). The same YANG models (like ietf-interfaces and OpenConfig) work across different vendors. In practice, there are still vendor-specific models for advanced features, but the principle is sound.

The Auth Puzzle: What Network APIs Use

Different network APIs handle authentication differently. The three you'll encounter most:

  • Basic auth: Username and password, base64-encoded in the Authorization header. Cisco RESTCONF defaults to this. Simple, but credentials go in every request.

  • Token/Bearer auth: Log in once, get a token, include the token in subsequent requests. NSO, Cisco DNA Center, and many management platforms use this.

  • API keys: A single long string in a header (usually X-API-Key). Common in cloud-managed platforms like Meraki.

Always use HTTPS. Even in a lab. Getting into the habit of using HTTP for speed is how credentials end up in packet captures.

Postman: The Right First Tool

Before writing any code, use Postman. It's a GUI HTTP client that makes REST API exploration fast and forgiving. You can build a request, see the full response, check headers, and iterate without writing a single line of Python.

Cisco offers a DevNet sandbox (devnetsandbox.cisco.com) with free, always-on IOS-XE instances. You can point Postman at a sandbox router, send your first GET to /restconf/data/ietf-interfaces:interfaces, and see the full interface list in seconds.

Once you understand what a request looks like in Postman, moving it to Python is straightforward. Postman even has a "Code" button that generates the equivalent Python requests call.

Practical Takeaway

Pick one device that supports RESTCONF and try a GET. You don't need to write automation first. Just explore: what does the interface config look like in JSON? What does the routing table look like? What YANG paths does this device expose?

That exploration is the fastest way to build the mental model you need before writing a single line of automation. REST APIs aren't magic. They're HTTP. And once you've seen a few responses, the rest makes sense quickly.

Watch the video

This is part of the Network Automation 101 series on YouTube.

Watch on YouTube →

Next in this series

How to Send a REST API GET Request in Postman →

Comments (0)

Please sign in to comment.

  • Be the first to comment.