From 8e976f9331598cef935fb549efa187282662deca Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 12:59:05 +0000 Subject: [PATCH] Add GET endpoint for /countries --- endpoints/countries.get.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/endpoints/countries.get.py b/endpoints/countries.get.py index e69de29..fe67f6c 100644 --- a/endpoints/countries.get.py +++ b/endpoints/countries.get.py @@ -0,0 +1,23 @@ +# 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("/countries", status_code=200, response_model=List[CountrySchema]) +async def get_countries(): + """Get list of countries from external API""" + async with httpx.AsyncClient() as client: + try: + response = await client.get("https://restcountries.com/v3.1/all") + response.raise_for_status() + return response.json() + except httpx.HTTPError: + raise HTTPException( + status_code=status.HTTP_503_SERVICE_UNAVAILABLE, + detail="Unable to fetch countries from external API" + ) \ No newline at end of file