2025-03-23 00:18:39 +01:00

25 lines
861 B
Python

from fastapi import APIRouter, HTTPException
people = [
{"name": "Alice", "age": 55, "country": "UK"},
{"name": "Bob", "age": 45, "country": "ESP"},
{"name": "Charlie", "age": 60, "country": "Nigeria"},
{"name": "David", "age": 52, "country": "UK"},
{"name": "Eve", "age": 48, "country": "ESP"}
]
router = APIRouter()
@router.get("/man")
async def get_people_over_50():
"""Fetches list of people over 50 years of age"""
over_50 = [p for p in people if p["age"] > 50]
return {
"method": "GET",
"_verb": "get",
"data": over_50
}
```
This endpoint defines a list of people with their name, age, and country. The `get_people_over_50` function filters the list to only include people whose age is greater than 50, and returns a dictionary with the method metadata and the filtered list of people.