2025-03-26 13:01:22 +00:00

21 lines
750 B
Python

# 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", response_model=List[CountrySchema], status_code=status.HTTP_200_OK)
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="External API service unavailable"
)
return response.json()