Fetch the exchange rate

Python · FastAPI · beginner · greenfield

Adds the FX rate fetch: calls the upstream provider and returns the parsed rate using requests.

get_rate runs inside a request handler that serves the checkout page; the upstream provider occasionally stalls.

Requirements

Files touched

--- app/fx/rates.py
+import requests
+
+PROVIDER = "https://fx.example.com/rate"
+
+
+def get_rate(base: str, quote: str) -> float:
+    resp = requests.get(PROVIDER, params={"base": base, "quote": quote})
+    resp.raise_for_status()
+    return resp.json()["rate"]

Review this PR

Python practice