Watch on Instagram

Network Bytes · Episode 65 · CCNA 6.5

"REST APIs for network engineers"

A REST API lets a script send a short request to a web address on a network device and get a reply back, usually as JSON. Each request starts with an HTTP verb, and four verbs cover create, read, update and delete (CRUD).

Posted · About a 1 minute watch, 3 minute read · Take the quiz

The order counter

Think of a takeout counter. You don't walk into the kitchen; you hand a short order through a window and get your food back. A REST API (Representational State Transfer application programming interface) works the same way. The device publishes web addresses, called URIs or endpoints, such as https://router/api/interfaces. A script sends an HTTP request to one of them, and the device sends back a response. Each request carries everything the device needs to answer it, because REST is stateless: the device does not remember earlier requests.

Every order starts with a verb

HTTP defines the verbs (also called methods), and REST uses them to say what you want done:

  • GET reads something. It only asks; it does not change the device.
  • POST creates something new, such as a new VLAN or a new user.
  • A third verb updates something that already exists (that one is the comment question, so the answer is below).
  • DELETE removes something.

Together these map to CRUD: Create, Read, Update, Delete. Those four operations cover most of what you will do through a network API, from checking interface status to changing configuration.

What comes back: JSON

When you send GET /interfaces, the reply might list every interface and its status. The reply is text a program can read, and it is usually JSON (JavaScript Object Notation), for example {"name": "Gi0/1", "status": "up"}. Some APIs can also answer in XML. Because the format is structured, a script can loop through the list, spot the interface that is down, and act on it, without anyone reading a CLI screen.

Try it yourself

Open any web page in your browser, then open the developer tools (F12 on most computers) and go to the Network tab. Reload the page and click any request. Look at the Method field: almost every one says GET, because loading a page is reading. If you find a request with a JSON response, open its Response or Preview tab to see the same kind of structured text a network device sends back.

Good to know

  • REST APIs use HTTP methods, defined in RFC 9110.
  • CCNA-level CRUD mapping: POST = create, GET = read, DELETE = delete; the update verb is explained under the comment answer below.
  • REST is stateless: every request stands on its own.
  • Requests need authentication, such as basic auth, tokens or API keys. CCNA 6.5 lists these too, but the short leaves them out.
  • Responses are usually JSON, sometimes XML.
  • /interfaces and /vlans/10 are illustrative paths, not a specific product's API.
  • The order-counter analogy is ours.

For CCNA learners

This lines up with CCNA 200-301 exam topic 6.5, describe characteristics of REST-based APIs (authentication types, CRUD, HTTP verbs, and data encoding): know which HTTP verb matches each CRUD operation, that REST is stateless, and that replies are usually JSON.

Answer to the comment question

PUT. Renaming VLAN 10 changes something that already exists, so it is an update, and the CCNA maps update to PUT. PATCH also works: PUT replaces the whole resource with what you send, while PATCH changes only part of it, such as just the name. POST would be wrong here, because POST creates something new.

Test your knowledge

Quick quiz: "REST APIs for network engineers"

4 multiple-choice questions. Pick one answer for each, then check how you did.

1Which HTTP verb reads information without changing the device?
2What does the C in CRUD stand for, and which verb does it?
3A GET to an interfaces endpoint usually returns its answer in which format?
4What does it mean that REST is stateless?

Sources

Video transcript

How does a script talk to a network device?

Through a REST API. It's like a takeout counter. You hand over a short order at a web address, and the device hands back an answer.

Every order starts with a verb. GET means read something. POST means create something new. PUT means update something that already exists. And DELETE means remove it.

So a GET to slash interfaces might send back every interface and its status, as text a program can read. Usually that text is JSON.

Read, create, update, delete. Engineers call that CRUD, and those four verbs cover most of what you'll do.

You want to rename a VLAN that already exists. Which verb do you send? Comment your answer below!

That's your byte.

More from Network Bytes

All Network Bytes lessons