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
- Map CRUD to HTTP verbs: POST, GET, PUT/PATCH, DELETE.
- Describe REST properties: client-server, stateless, uniform interface, cacheable.
- Read a URI, headers, body and response code.
- Name authentication methods: basic, API keys, bearer tokens, OAuth.
- Recognise data encodings: JSON, XML, YAML.
CRUD and HTTP verbs
| CRUD | HTTP verb | Example |
|---|---|---|
| Create | POST | Add a new VLAN or site |
| Read | GET | List devices |
| Update | PUT (replace) / PATCH (modify) | Change an interface description |
| Delete | DELETE | Remove 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 process | On IOS XE: whether RESTCONF and NETCONF are running. |
Exam traps
- POST creates, PUT replaces, PATCH changes part, GET reads, DELETE removes.
- 401 means not authenticated; 403 means authenticated but not allowed.
- REST is stateless: the token goes with every request.
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.