Lesson Overview
Modern network automation depends on APIs, structured data, and automation tools that allow software to read network state and make repeatable configuration changes. REST APIs commonly use HTTP or HTTPS to exchange requests and responses, while CRUD describes the basic operations used to create, read, update, and delete resources.
This lesson explains how REST, HTTP methods, status codes, and JSON work together in network programmability. It also introduces Ansible and Terraform as automation and Infrastructure-as-Code tools: Ansible commonly executes task-based configuration and operational workflows, while Terraform uses a declarative model to build and maintain desired infrastructure state. The focus is on understanding how these technologies fit into controller-based and API-driven network operations.
Learning objectives
- By the end of this lesson, a learner should be able to:
- Explain REST and identify a resource, URI/endpoint, request, response, header, and body.
- Map CRUD operations to common HTTP methods and interpret common HTTP status codes.
- Recognize common API authentication methods and explain why HTTPS is important.
- Read JSON objects, arrays, keys, values, nested structures, and basic data types.
- Describe Ansible components such as inventory, playbooks, modules/collections, variables, and templates.
- Describe Terraform components such as HCL configuration, providers, resources, state, plan, and apply.
- Compare Ansible and Terraform at a CCNA level and identify common use cases for each.
- Follow a safe automation workflow: baseline → change → verify → rollback if required.
|
Key idea: APIs provide a programmable interface, JSON commonly carries the data, and tools such as Ansible and Terraform automate repeatable changes using those interfaces. |
1. REST fundamentals
1.1 What is REST?
REST (Representational State Transfer) is an architectural style commonly used to build web APIs. In networking, a REST API allows an application, script, automation tool, or controller to read information from a platform and request changes without manually logging in to every device.
A REST API exposes resources. A resource can represent a device, interface, VLAN, site, policy, user, route, wireless network, or many other manageable objects. The client identifies the resource by a URI and uses an HTTP method to state the desired action.
Client: the script, application, automation platform, or API tool sending the request.
Server/API endpoint: the controller or device that exposes the REST interface.
Resource: the object being read or changed, such as a device or interface.
URI/URL: the path that identifies where the resource is exposed.
Method: GET, POST, PUT, PATCH, DELETE, and other HTTP methods.
Headers: metadata such as authentication, accepted format, and content type.
Body: optional data sent with the request or returned in the response, commonly JSON.
Status code: a numeric result such as 200, 201, 401, 404, or 500.
1.2 REST is normally stateless
Stateless means the server does not need to remember a previous request in order to understand the next request. Each request normally carries the information needed to process it, such as the resource URI, method, authentication context, and required data. Authentication systems can still use tokens or sessions; the key REST idea is that the request itself is self-contained enough for the server to act on it.
1.3 REST resource examples
|
Resource idea |
Example URI |
Possible operation |
|
Device inventory |
/api/v1/devices |
GET all devices |
|
Single device |
/api/v1/devices/R1 |
GET / PATCH device |
|
Interfaces |
/api/v1/devices/R1/interfaces |
GET interfaces |
|
VLANs |
/api/v1/vlans |
GET / POST VLANs |
|
Policy |
/api/v1/policies/branch-access |
GET / PATCH policy |
2. CRUD and HTTP methods
2.1 CRUD
CRUD is a simple way to describe the four basic operations performed on data: Create, Read, Update, and Delete. Network APIs often expose these operations using standard HTTP methods.
|
CRUD |
Common HTTP method |
Typical meaning |
|
Create |
POST |
Create a new resource in a collection. |
|
Read |
GET |
Retrieve a resource or collection. |
|
Update |
PUT |
Replace the representation of a resource. |
|
Update |
PATCH |
Modify only selected fields of a resource. |
|
Delete |
DELETE |
Remove a resource. |
|
Exam note: The CRUD-to-HTTP mapping is a common convention, but the actual API documentation defines exactly which methods are supported for each endpoint. |
2.2 GET - Read
GET asks the API to return data. It should not be used…
