6.4 REST-Based APIs
Key Takeaways
- REST APIs use HTTP methods (GET, POST, PUT, PATCH, DELETE) to interact with network controllers and devices.
- APIs return data in structured formats like JSON or XML, which can be processed by scripts and applications.
- HTTP status codes indicate success (200), creation (201), client error (400), or server error (500).
- REST is stateless — each request contains all the information needed; the server does not remember previous requests.
- CRUD operations map to HTTP methods: Create=POST, Read=GET, Update=PUT/PATCH, Delete=DELETE.
REST-Based APIs
REST (Representational State Transfer) is an architectural style for building APIs (Application Programming Interfaces). REST APIs are the primary way applications interact with SDN controllers and network devices.
What Is a REST API?
A REST API allows software programs to communicate over HTTP/HTTPS. Instead of logging into a CLI and typing commands, you send HTTP requests to a URL endpoint and receive structured data (usually JSON) in return.
Example: Get a list of network devices from Cisco DNA Center
GET https://dnacenter.example.com/api/v1/network-device
Authorization: Bearer <token>
Content-Type: application/json
Response (JSON):
{
"response": [
{
"hostname": "SW-Floor1",
"managementIpAddress": "10.0.0.10",
"platformId": "C9300-48T",
"softwareVersion": "17.9.1",
"reachabilityStatus": "Reachable"
}
]
}
REST Characteristics
| Characteristic | Description |
|---|---|
| Stateless | Each request is independent; server doesn't remember previous requests |
| Client-Server | Client sends requests, server processes and responds |
| Uniform Interface | Standard HTTP methods and URL structure |
| Cacheable | Responses can be cached for performance |
| Layered | Client doesn't need to know if it's connected directly to the server or through intermediaries |
HTTP Methods (CRUD Operations)
| HTTP Method | CRUD Operation | Purpose | Example |
|---|---|---|---|
| GET | Read | Retrieve data | Get list of VLANs |
| POST | Create | Create new resource | Create a new VLAN |
| PUT | Update (full) | Replace entire resource | Replace a device's entire configuration |
| PATCH | Update (partial) | Modify part of a resource | Change a VLAN's name |
| DELETE | Delete | Remove a resource | Delete a VLAN |
HTTP Status Codes
| Code | Category | Meaning |
|---|---|---|
| 200 | Success | OK — request succeeded |
| 201 | Success | Created — new resource created successfully |
| 204 | Success | No Content — request succeeded, no data to return |
| 400 | Client Error | Bad Request — malformed request syntax |
| 401 | Client Error | Unauthorized — authentication required |
| 403 | Client Error | Forbidden — authenticated but not authorized |
| 404 | Client Error | Not Found — resource doesn't exist |
| 500 | Server Error | Internal Server Error — server encountered an error |
Status Code Categories
| Range | Category | Meaning |
|---|---|---|
| 1xx | Informational | Request received, processing |
| 2xx | Success | Request successfully processed |
| 3xx | Redirection | Further action needed |
| 4xx | Client Error | Problem with the request |
| 5xx | Server Error | Problem with the server |
REST API Authentication
APIs require authentication to prevent unauthorized access:
| Method | How It Works |
|---|---|
| Basic Auth | Username:password encoded in Base64 (weak) |
| API Key | Unique key included in header or URL parameter |
| Token-based | Login with credentials → receive token → include token in subsequent requests |
| OAuth 2.0 | Industry standard for delegated authorization |
REST APIs in Network Automation
| Platform | API Use Case |
|---|---|
| Cisco DNA Center | GET devices, POST configurations, monitor network health |
| Cisco Meraki | Manage cloud-managed networks via REST API |
| Cisco ACI | Data center fabric management via REST API |
| Cisco SD-WAN | WAN management and policy deployment |
On the Exam: Know the HTTP methods and their CRUD mappings. Understand that REST APIs are stateless and use JSON for data exchange. Be able to identify what a GET, POST, PUT, or DELETE request does in a networking context.
Which HTTP method is used to retrieve data from a REST API without modifying anything?
What does the HTTP status code 401 indicate?
Which characteristic of REST means that each API request must contain all information needed for the server to process it?