Add GET endpoint for /countries
This commit is contained in:
parent
9c62627876
commit
1db22e13bf
@ -12,12 +12,10 @@ router = APIRouter()
|
|||||||
async def get_countries():
|
async def get_countries():
|
||||||
"""Get list of countries from external API"""
|
"""Get list of countries from external API"""
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
try:
|
response = await client.get("https://restcountries.com/v3.1/all")
|
||||||
response = await client.get("https://restcountries.com/v3.1/all")
|
if response.status_code != 200:
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
|
||||||
except httpx.HTTPError:
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||||
detail="Unable to fetch countries from external API"
|
detail="Unable to fetch countries from external API"
|
||||||
)
|
)
|
||||||
|
return response.json()
|
Loading…
x
Reference in New Issue
Block a user