{
  "id": 9798217,
  "title": "What building an API aggregator taught me about calling other people's APIs",
  "url": "https://urgent.news/2026/09/25/what-building-an-api-aggregator-taught-me-about-calling-other-peoples",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-25T17:24:16.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/gunjan-redu/what-building-an-api-aggregator-taught-me-about-calling-other-peoples-apis-47ll"
  },
  "original_language": "en",
  "account": "I am an educator in the realm of programming. As I delve into the world of FastAPI, I find myself making numerous calls to external APIs. However, I have never had the opportunity to interact with an external API until now. Consequently, I decided to create a service that relies completely on the APIs of others - weather, currency exchange, and news. This endeavor taught me invaluable lessons. The process of linking API calls: Utilizing Open-meteo's weather API, I had to employ another API to obtain the latitude and longitude of any city worldwide, using only its name. Thus, the client's city name was used to fetch the corresponding coordinates from the first API, which were then passed as input to the weather API. The output of one API functioned as the input for the subsequent one. Who is responsible for the failure: I devised a method to handle failures within the system, ensuring the client is informed of the cause. If the request fails due to a timeout error, the client is notified, preventing further attempts. In case our own server encounters an error, the client is informed. A 500 error is returned if our server fails, a 502 error if the external API provides an invalid response, and a 504 error if the external API service times out. I tested this by setting a timeout of 0.001 seconds, causing every call to fail. Previously, an intrusive 500 traceback was displayed. Now, a clean 504 error is presented, indicating \"weather service timed out.\" Graceful degradation: I developed an aggregate endpoint that amalgamates the responses from all three APIs, presenting the information to the client. Upon entering a city name, the service retrieves the weather, currency conversion, and news. If any of these three APIs fail, only the responses from the successful APIs are returned, along with the name of the API causing the error, and a 404 error is given if the client enters an unrecognized city name. Caching: I incorporated a TTL cache into my project, storing every response for 5 minutes to conserve resources. However, TTL cache has its drawbacks. If the system is stopped and restarted for any reason, numerous requests may be triggered, a phenomenon known as cache stampede. Additionally, TTL cache exists solely within the process; if other workers in the project require its use, it will not function. Testing with mocks: I established tests using Pytest, covering all endpoints, including failure scenarios. The project includes code for what would happen if external APIs failed or returned invalid responses. This code was untestable, as it is impossible to simulate an API failure during testing. To circumvent this, I simulated the disasters myself during tests, replacing the httpx library with a fake that returns predefined responses such as a 500 error or a timeout. My error-handling code functions in tandem with these simulated failures, verifying that the code responds correctly without any real service being down. Through this project, I have not only learned how to interact with external APIs but also gained proficiency in using Pytest. The GitHub repository containing the project code can be accessed at https://github.com/Gunjan-redu/api-aggregator.",
  "summary": "I am a teacher, I teach coding to kids. I am trying to learn backend development. In my journey to learn FastAPI I got to make many APIs. But I'd never gotten a chance to use an external API. So I built a service that lives entirely on other people's APIs- weather, currency and news. Here's what it taught me. Chaining API calls- I used Open-meteo's weather API, which requires the latitudes and…",
  "key_points": [
    "Created API aggregator using Open-meteo, currency exchange, and news APIs",
    "Implemented error handling for timeouts, invalid responses, and server errors",
    "Incorporated TTL cache with cache stampede and worker independence considerations"
  ],
  "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."
}