Making HTTP Requests in Python
import requests
url = "https://api.github.com/users/octocat"
response = requests.get(url, timeout=5.0)
if response.status_code == 200:
data = response.json()
print(f"User: {data['name']}, Public Repos: {data['public_repos']}")
Always provide a timeout=... parameter to prevent slow or unresponsive servers from hanging your Python program forever.
Quick Summary
- Use HTTP methods (GET, POST, PUT, DELETE) to communicate with external web endpoints.
- Next, we parse and serialize data with JSON & Data Exchange.