{
  "id": 11468272,
  "title": "Python APIs: Making HTTP Requests for Beginners",
  "url": "https://urgent.news/2026/10/02/python-apis-making-http-requests-for-beginners",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-02T15:17:29.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/sameerqaisar17/python-apis-making-http-requests-for-beginners-201d"
  },
  "original_language": "en",
  "account": "Making HTTP requests in Python allows apps to fetch data from the internet, similar to how weather apps, social media, and online stores communicate with servers. An API (Application Programming Interface) enables two programs to communicate, much like a waiter bringing information from a kitchen.\n\nWithout APIs, manually fetching data like weather would require opening a browser, navigating to a site, reading the temperature, and copying it down repeatedly. This process is not scalable or automatable. APIs enable direct communication, making the process efficient and automated.\n\nUsing the Python `requests` library, you can fetch data from an API. For example, the following code retrieves live data from GitHub's API:\n\n```python\nimport requests\nresponse = requests.get(\"https://api.github.com/users/torvalds\")\ndata = response.json()\nprint(data[\"name\"])\nprint(data[\"public_repos\"])\n```\n\nThis code outputs Linus Torvalds and 100, fetching live data from GitHub.\n\nThe code works as follows:\n1. `import requests` loads the necessary library.\n2. `requests.get(url)` sends an HTTP GET request to the specified URL.\n3. `.json()` converts the response to a Python dictionary.\n4. `data[ \"name\" ]` accesses a specific field in the dictionary.\n\nThe server responds with HTTP status codes, indicating the success or failure of the request. Common status codes include 200 OK for success, 404 Not Found when the URL doesn't exist, 403 Forbidden when access is denied, and 500 Server Error when the server breaks. Always check the status code to handle errors appropriately.\n\nHere is a real example using a weather API:\n\n```python\nimport requests\nurl = \"https://api.open-meteo.com/v1/forecast\"\nparams = {\n\"latitude\": 24.86,\n\"longitude\": 67.01,\n\"current_weather\": True\n}\nresponse = requests.get(url, params=params)\ndata = response.json()\nprint(f\"Temperature: {data['current_weather']['temperature']}°C\")\n```\n\nThis example retrieves the temperature in degrees Celsius from the Open-Meteo weather API.\n\nCommon mistakes beginners make include not installing the `requests` library, forgetting to use `.json()` to extract data, not handling errors, and hardcoding API keys directly in the code. To avoid these issues, install the library with `pip install requests`, always use `.json()` to access the data, handle errors by checking the status code, and store API keys in environment variables instead of the code.",
  "summary": "📌 Quick Info Topic: Making HTTP requests in Python Target Audience: Beginners who know functions and JSON Goal: Understand how to fetch data from the internet with Python 1. Introduction \"Every app I used was pulling data from somewhere. Weather apps, social media, online stores — they all talk to servers. Then I learned about APIs and HTTP requests, and I could finally build programs that talk…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}