From b8e71909a9a5d14a3610b4964c2a69d31b2d8212 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 13:03:51 +0000 Subject: [PATCH] Add get endpoint for states --- endpoints/states.get.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 endpoints/states.get.py diff --git a/endpoints/states.get.py b/endpoints/states.get.py new file mode 100644 index 0000000..82a4eef --- /dev/null +++ b/endpoints/states.get.py @@ -0,0 +1,21 @@ +# Entity: Country + +from fastapi import APIRouter, HTTPException, status +from typing import List +import httpx +from core.models.country import Country +from core.schemas.country import CountrySchema + +router = APIRouter() + +@router.get("/states", status_code=200, response_model=List[CountrySchema]) +async def get_countries(): + """Get list of countries from external API""" + async with httpx.AsyncClient() as client: + response = await client.get("https://restcountries.com/v3.1/all") + if response.status_code != 200: + raise HTTPException( + status_code=status.HTTP_503_SERVICE_UNAVAILABLE, + detail="Unable to fetch countries data" + ) + return response.json() \ No newline at end of file