HTTP POST with JSON Body

Send a POST request with a JSON payload.

Code

Python
import requests

payload = {"name": "Alice", "age": 30}
response = requests.post(
    "https://api.example.com/users",
    json=payload,
    headers={"Authorization": "Bearer token123"}
)

print(response.status_code)
print(response.json())

Line-by-line explanation

Expected output

201
{'id': 1, 'name': 'Alice'}

Related snippets

Related DuskTools