📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero HTTP Requests

HTTP Requests

5 min read Quiz at the end
The requests library makes HTTP easy: requests.get(url) for GET and requests.post(url, json=data) for POST. Check r.status_code, parse JSON with r.json(), and always set a timeout to prevent hanging.

Making HTTP Requests

pip install requests

import requests

# GET
res = requests.get("https://api.github.com/users/torvalds")
data = res.json()
print(data["name"])

# POST
res = requests.post("https://httpbin.org/post",
    json={"key": "value"},
    headers={"Authorization": "Bearer TOKEN"})

print(res.status_code)
Topic Quiz · 5 questions

Test your understanding before moving on

1. Which library makes HTTP requests?
💡 The requests library is the standard Python HTTP client: pip install requests.
2. Which method makes a GET request?
💡 requests.get(url) makes an HTTP GET request.
3. How do you parse a JSON response?
💡 .json() method on a response object parses the JSON body.
4. What does res.status_code return?
💡 res.status_code returns the HTTP status code like 200, 404, 500.
5. How do you send JSON in a POST?
💡 requests.post(url, json=dict) sends JSON and sets Content-Type automatically.