API Gateway Problem2026-05-23
Context
I am building a microservices architecture in Python using FastAPI and requests.
The system consists of an API Gateway and two downstream services:
- API Gateway (Port 8000): Acts as a reverse proxy routing
/usersand/weathertraffic. - User Service (Port 8001): Returns basic JSON data.
- Weather Service (Port 8002): Reconstructs dynamic path/query parameters using FastAPI's
Requestobject and forwards them to the Open-Meteo API.
Current Code
gateway.py
from fastapi import FastAPI
import requests
app = FastAPI()
@app.get("/users")
def get_users():
return requests.get("http://127.0.0.1:8001/users").json()
@app.get("/weather")
def get_weather():
weather_url = "https://api.open-meteo.com/v1/forecast?latitude=41.6639&longitude=-83.5552¤t_weather=true"
return requests.get(f"http://127.0.0.1:8002/weather/{weather_url}").json()
users.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/users")
def get_users():
return {"Zayeem": "SWE", "Ahtasham": "BCE"}
weather.py
import requests
from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/weather/{weather_url:path}")
def get_weather(weather_url: str, request: Request):
if request.url.query:
weather_url = f"{weather_url}?{request.url.query}"
response = requests.get(weather_url)
if not response.ok:
return {"error": "Downstream request failed", "details": response.text}
return response.json()
Notes
This setup shows two common gateway concerns:
- Simple request forwarding to another internal service
- Rebuilding dynamic path and query parameters before proxying to an external API