Add get endpoint for states

This commit is contained in:
Backend IM Bot 2025-03-26 13:04:38 +00:00
parent 425b9f1462
commit 1a63e5aaf2

View File

@ -2,20 +2,20 @@
from fastapi import APIRouter, HTTPException, status
from typing import List
import httpx
from core.models.country import Country
from core.schemas.country import CountrySchema
import httpx
router = APIRouter()
@router.get("/states", status_code=200, response_model=List[CountrySchema])
@router.get("/states", response_model=List[CountrySchema], status_code=status.HTTP_200_OK)
async def get_countries():
"""Get list of countries from external API"""
"""Get list of countries from third party 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"
detail="Unable to fetch countries from external API"
)
return response.json()