REST API stands for Representational State Transfer Application Programming Interface.
It’s a standard way for two systems to communicate over the web (HTTP/HTTPS) — often between a client (like Python script or Ansible) and a server (like a network device or SDN controller).
In simple terms:
👉 A REST API allows you to interact with a system (get data, configure, update, or delete something) using HTTP requests — just like how your browser communicates with websites.
⚙️ Why REST APIs Matter in Networking
In modern networks:
- Devices (Cisco, Juniper, Fortinet, etc.) and controllers (like OpenDaylight, Cisco DNA Center, VMware NSX) expose REST APIs.
- Engineers can automate tasks (like getting interface status, pushing configurations, or monitoring health) using API calls instead of manual CLI.
Example:
Instead of logging into 50 routers to check interface status,
you can run one Python script that uses REST APIs to fetch all interface data.
🧩 Key Concepts of REST API
| Concept | Description |
|---|---|
| Client | The system or application making the API request (e.g., Python script, Postman, Ansible) |
| Server | The system that provides the API (e.g., router, firewall, controller) |
| Resource | The object you’re working with (e.g., interface, VLAN, route, policy) |
| URI (Uniform Resource Identifier) | The address to access a resource (e.g., /api/v1/interfaces) |
| HTTP Methods | Define what action to perform on a resource |
🔠 Common HTTP Methods
| Method | Purpose | Example |
|---|---|---|
| GET | Retrieve information | Get interface status |
| POST | Create new data/configuration | Add a new VLAN |
| PUT | Update/replace data | Change an interface IP |
| PATCH | Modify part of a resource | Update interface description |
| DELETE | Remove data/configuration | Delete a VLAN |
🧾 Typical REST API Request Structure
A REST API request looks like this:
Method: GET
URL: https://192.168.1.1/api/v1/interfaces
Headers:
Content-Type: application/json
Authorization: Bearer <token>
Response (from device or server):
{
"interfaces": [
{"name": "GigabitEthernet0/0", "status": "up"},
{"name": "GigabitEthernet0/1", "status": "down"}
]
}
💡 Key Characteristics of REST APIs
- Stateless: Each request is independent; the server doesn’t remember previous ones.
- Uses HTTP verbs: GET, POST, PUT, DELETE, etc.
- Uses URIs to identify resources.
- Supports multiple data formats: Commonly JSON, sometimes XML.
- Client-Server separation: Clear boundary between what requests and what responds.
- Cacheable: Responses can be cached for performance.
🧰 Common Tools to Work with REST APIs
| Tool | Use |
|---|---|
| Postman | GUI-based tool to test and visualize API calls |
| cURL | Command-line tool for sending HTTP requests |
| Python (Requests library) | Programmatically interact with APIs |
| Ansible / Terraform | Use APIs for automation/infrastructure as code |
🐍 Example: Python Script Using REST API
import requests
import json
url = "https://192.168.1.1/api/v1/interfaces"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer your_token_here"
}
response = requests.get(url, headers=headers, verify=False)
data = response.json()
for interface in data["interfaces"]:
print(interface["name"], "-", interface["status"])
✅ This script retrieves interface status from a network device that supports REST APIs.
🌐 Example REST API Endpoints (Networking)
| Vendor | API Example | Description |
|---|---|---|
| Cisco DNA Center | /dna/intent/api/v1/network-device | Get all devices |
| Fortinet FortiGate | /api/v2/monitor/system/interface/ | Get interface list |
| Juniper Junos | /rpc/get-interface-information | Get interface info |
| OpenDaylight | /restconf/operational/network-topology:network-topology | Get network topology |
| Arista eAPI | /command-api | Send CLI commands via JSON-RPC |
✅ Benefits of Using REST APIs
- Automation: Eliminate manual configuration
- Integration: Connect network, cloud, and monitoring systems
- Speed: Fast configuration and data collection
- Consistency: Apply uniform settings across devices
- Scalability: Manage hundreds of devices easily
🧭 Summary
| Concept | Description |
|---|---|
| Full Form | Representational State Transfer API |
| Purpose | Communication between client and server using HTTP |
| Data Format | JSON / XML |
| Common Methods | GET, POST, PUT, DELETE |
| Use in Networking | Automate configuration, monitoring, and integration |
| Tools | Postman, Python Requests, Ansible |
Leave a comment