feat: Update endpoint get-request
This commit is contained in:
parent
bc415876ac
commit
c0d1e0182a
@ -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