feat: Update endpoint test-endpoint
This commit is contained in:
parent
3e8c5a47ef
commit
67cd33c83f
@ -0,0 +1,16 @@
|
||||
from fastapi import FastAPI
|
||||
import requests
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/countries")
|
||||
def get_all_countries():
|
||||
url = "https://restcountries.com/v3.1/all"
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response.raise_for_status() # Raise an error for bad responses (4xx and 5xx)
|
||||
countries = response.json()
|
||||
return [{"name": country.get("name", {}).get("common")} for country in countries]
|
||||
except requests.exceptions.RequestException as e:
|
||||
return {"error": f"Failed to fetch countries: {str(e)}"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user