2025-03-22 23:59:53 +01:00

28 lines
904 B
Python

from fastapi import APIRouter, HTTPException
people = [
{"name": "Alice", "age": 55, "country": "UK"},
{"name": "Bob", "age": 45, "country": "US"},
{"name": "Charlie", "age": 60, "country": "ESP"},
{"name": "David", "age": 35, "country": "UK"},
{"name": "Eve", "age": 52, "country": "US"}
]
router = APIRouter()
@router.get("/human")
async def get_people_over_50():
"""Fetches list of people over 50 years of age"""
if request.method != "GET":
raise HTTPException(status_code=405, detail="Method Not Allowed")
over_50 = [person for person in people if person["age"] > 50]
return {
"method": "GET",
"_verb": "get",
"data": over_50
}
```
This endpoint filters the `people` list to only include those whose age is over 50, and returns that filtered list in the response data. It also includes the required method metadata fields.