REST APIs



Installation



pip install requests


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Make HTTP Calls with Ease Using requests



• Full HTTP Client
• Simplifies authentication, headers and response tracking
• Great for REST API calls or any HTTP request

# Simple example: Making HTTP request
import requests
requests.get("https://api.github.com")

# Output
<Response [200]>


import requests
from pprint import pprint

router = {"ip""10.10.21.48",
      "port""443",
          "user""cisco",
          "pass""cisco_1234!"}

headers = {"Accept""application/yang-data+json"}

u = "https://{}:{}/restconf/data/interfaces/interface=GigabitEthernet1"

u = u.format(router["ip"], router["port"])

r = requests.get(u,
     headers = headers,
     auth=(router["user"], router["pass"]),
     verify=False)

pprint(r.text)

import json

api_data = r.json()

interface_name = api_data["Cisco-IOS-XE-interfaces-oper:interface"]["name"]

interface_name



Index