6.5 Describe REST API characteristics: authentication, CRUD, HTTP verbs, data encoding

CCNA 200-301 v1.1 · 6.0 Automation and Programmability

A REST API lets programs talk to a controller or device over HTTPS. Each resource has a URI, HTTP verbs say what to do with it (CRUD), the body is usually JSON, and every request is authenticated. For the CCNA you read a REST call and say what it does.

What you must know

CRUD and HTTP verbs

CRUDHTTP verbExample
CreatePOSTAdd a new VLAN or site
ReadGETList devices
UpdatePUT (replace) / PATCH (modify)Change an interface description
DeleteDELETERemove a site

REST is stateless: every request carries everything the server needs, including authentication. Responses use status codes: 2xx success (200 OK, 201 Created, 204 No Content), 4xx client errors (400 bad request, 401 unauthorized, 403 forbidden, 404 not found), 5xx server errors.

A request and its answer

GET https://catalyst-center.example.com/dna/intent/api/v1/network-device
Accept: application/json
X-Auth-Token: eyJhbGciOiJIUzI1NiJ9...

HTTP/1.1 200 OK
Content-Type: application/json
{"response": [{"hostname": "SW1", "managementIpAddress": "10.99.0.11", "platformId": "C9300-48P"}]}

The script first gets a token with a POST (1), then sends it in a header with each request and reads the JSON answer (2). Other APIs use basic authentication (username and password in a header, only over HTTPS), an API key, or OAuth tokens issued by an identity provider.

Data is encoded as JSON (the most common), XML (NETCONF, older APIs) or YAML (Ansible files, readable configuration). The Content-Type and Accept headers say which one is sent and wanted.

Commands

curl -X GET <uri> -H 'Accept: application/json'Send a REST request from the command line.
show platform software yang-management processOn IOS XE: whether RESTCONF and NETCONF are running.

Exam traps

Check yourself

Which verb creates a new resource?
POST.
A request returns 404. What does it mean?
The resource at that URI does not exist.
Which header tells the server you want JSON back?
Accept: application/json.

More topics in 6.0 Automation and Programmability