🧠 What is a REST API?

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:

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

ConceptDescription
ClientThe system or application making the API request (e.g., Python script, Postman, Ansible)
ServerThe system that provides the API (e.g., router, firewall, controller)
ResourceThe 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 MethodsDefine what action to perform on a resource

🔠 Common HTTP Methods

MethodPurposeExample
GETRetrieve informationGet interface status
POSTCreate new data/configurationAdd a new VLAN
PUTUpdate/replace dataChange an interface IP
PATCHModify part of a resourceUpdate interface description
DELETERemove data/configurationDelete 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


🧰 Common Tools to Work with REST APIs

ToolUse
PostmanGUI-based tool to test and visualize API calls
cURLCommand-line tool for sending HTTP requests
Python (Requests library)Programmatically interact with APIs
Ansible / TerraformUse 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)

VendorAPI ExampleDescription
Cisco DNA Center/dna/intent/api/v1/network-deviceGet all devices
Fortinet FortiGate/api/v2/monitor/system/interface/Get interface list
Juniper Junos/rpc/get-interface-informationGet interface info
OpenDaylight/restconf/operational/network-topology:network-topologyGet network topology
Arista eAPI/command-apiSend CLI commands via JSON-RPC

Benefits of Using REST APIs


🧭 Summary

ConceptDescription
Full FormRepresentational State Transfer API
PurposeCommunication between client and server using HTTP
Data FormatJSON / XML
Common MethodsGET, POST, PUT, DELETE
Use in NetworkingAutomate configuration, monitoring, and integration
ToolsPostman, Python Requests, Ansible
renjithbs Avatar

Posted by

Leave a comment