NetAuto Academy

APIs and REST for Network Engineers

Endpoints, Resources, and Parameters

Intermediate11 min read

What you'll learn

  • What a REST 'resource' is, and how a URL identifies one
  • The difference between a path parameter and a query parameter
  • How to construct a correct request for a specific device and a filtered result
  • How this compares to devices.csv-style inventory addressing
🎓 Teach This Lesson

Listen to a guided explanation of this lesson.

Spoken narration isn't supported in this browser.

A URL names a resource

In REST, a URL identifies a resource — a specific thing the API knows about. /devices/SW1/interfaces doesn't describe an action; it names "SW1's interfaces." The HTTP method (GET, so far) is what says what to do with it.

a resource-oriented URL
GET /devices/SW1/interfaces
   ^devices  ^SW1  ^interfaces
   resource  which one   sub-resource

Every segment of the path narrows down which resource this request is about — the URL structure itself carries meaning, unlike a CLI command's flat argument list.

Quick checkConcept check
In REST, what does a URL like /devices/SW1/interfaces represent?

Path parameters: which resource

The SW1 in /devices/SW1/interfaces is a path parameter — part of the URL itself, identifying exactly which device.

path_parameter.py
import requests

for hostname in ["SW1", "SW3"]:
  response = requests.get(f"http://127.0.0.1:8765/devices/{hostname}/interfaces")
  print(hostname, "->", response.status_code, response.json()["hostname"])

An f-string builds a different URL per device — the same 'one pattern, many devices' idea as Jinja2's {% for %} loop and Ansible's loop:, now applied to constructing a URL.

output
SW1 -> 200 SW1
SW3 -> 200 SW3

Real, verified output — the same request pattern, a different device each time, just by changing the path parameter.

Quick checkIdentify the correct code
Given hostname = "SW2", which f-string correctly builds the URL for SW2's interfaces?

Query parameters: filtering the result

A query parameter narrows down what's returned, without naming a different resource. It's appended after a ?:

query_parameter.py
response = requests.get(
  "http://127.0.0.1:8765/devices/SW1/interfaces",
  params={"status": "up"},
)
print(response.url)
print(response.json())

requests builds the ?status=up query string for you from the params dict — no manual string concatenation needed.

output
http://127.0.0.1:8765/devices/SW1/interfaces?status=up
{'hostname': 'SW1', 'interfaces': [{'name': 'GigabitEthernet1/0/1', 'status': 'up'}]}

Real, verified output — SW1 has two interfaces total, but only the one matching status=up came back. The resource (SW1's interfaces) didn't change; what's returned about it did.

Quick checkPredict output
Using params={"status": "down"} against SW1's interfaces (from Lesson 2's data), how many interfaces come back?

Path parameter vs. query parameter

Path parameter
  1. /devices/SW1/interfacespart of the URL structure
  2. Identifies WHICH resource
  3. Required — the URL doesn't make sense without it
Query parameter
  1. ?status=upappended after ?
  2. Filters WHAT's returned about that resource
  3. Usually optional — omit it, get everything

devices.csv addressed one thing; this addresses two

devices.csv rows each named one device. A REST URL like /devices/SW1/interfaces names both a device (path parameter) and a sub-resource of it (interfaces) — with query parameters layered on top to filter further. More structure than a flat CSV row, for a genuinely more structured target.

Quick checkScenario
A request needs to fetch SW3's VLANs, filtered to only those named MGMT. Which two mechanisms does this require together?

Key takeaways

  • A REST URL names a resource; the HTTP method says what to do with it.
  • A path parameter (like SW1 in /devices/SW1/interfaces) is part of the URL and identifies which resource — required, and usually built with an f-string.
  • A query parameter (like ?status=up) filters what's returned about that resource — usually optional, and requests builds it for you from a params dict.
  • The two are combined routinely, not alternatives — verified directly against this module's own mock API.