Network automation lab 4 of 27

HTTP and REST with RESTCONF: curl, status codes and Python requests

Take a real router's REST API apart with curl: the HTTP request and response, authentication, media types, URLs built from YANG, every write method and its status code, a request that fails three different ways, and an RPC, then read it all from Python with requests.

Run this lab

It needs Lite: its 2 nodes are set to 2 vCPU and 5,120 MB in total. That fits the free demo too.

In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 04 - HTTP and REST with RESTCONF - curl status codes and Python requests

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

Level
Beginner
Time
About 70 minutes
Nodes need
2 vCPU, 5,120 MB
Smallest plan
Lite

The scenario

Kestrel Freight's developers want to build a self-service portal that reads and changes router settings. Before they write any code, they need someone on the network team who understands the router's REST API inside out: what a request really looks like on the wire, which header picks the data format, how a URL is built, which status code means what, and how to read an error. That's you, and the API is RESTCONF on the IOS XE router xe1.

DeviceAddressAPI
devbox10.10.20.10/24curl, Python 3 with requests
xe110.10.20.21/24 (Gi1)RESTCONF at https://xe1/restconf (HTTPS, port 443), self-signed certificate

What you’ll practise

  • Identify the parts of an HTTP request and response (method, URL, headers, status code, body)
  • Authenticate with HTTP Basic and choose JSON or XML with the Accept and Content-Type headers
  • Construct RESTCONF URLs for containers, list entries and leaves, with query parameters
  • Use GET, POST, PUT, PATCH and DELETE and explain the codes 200, 201, 204, 400, 401, 404 and 409
  • Troubleshoot failed requests from the status code, the error body and the documentation, and call a REST API from Python

The tasks

  1. Look at one request and response in full
  2. Authenticate, and see what Basic really sends
  3. Choose the format with Accept
  4. Build URLs from the data model
  5. Call the API from Python
  6. Use every write method and learn its status code
  7. Troubleshoot three failing requests
  8. RPCs on a REST API, and saving

The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.

Topology and devices

The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.

Topology of HTTP and REST with RESTCONF - curl status codes and Python requests2 nodes and 1 network, 2 links. Every link is listed as text below the diagram.devboxxe1Mgmteth0Gi1
2 nodes and 1 network, with the interface names each link uses. On a narrow screen, scroll the diagram sideways.
Nodes in HTTP and REST with RESTCONF: curl, status codes and Python requests, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB
xe1Cisco CSR 1000vcsr1000vng-universalk9.17.03.08a-serial1 vCPU, 4,096 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation - CCNA and CCNP Automation guided labs.

  3. Open 04 - HTTP and REST with RESTCONF - curl status codes and Python requests and start its nodes, then open Lab Tasks for the scenario and the steps.

The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.

More Network automation labs

All Network automation labs

Related labs in other courses

CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.