28 lines
959 B
Python
28 lines
959 B
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
people = [
|
|
{"id": 1, "name": "Alice", "age": 55},
|
|
{"id": 2, "name": "Bob", "age": 45},
|
|
{"id": 3, "name": "Charlie", "age": 60},
|
|
{"id": 4, "name": "David", "age": 35},
|
|
{"id": 5, "name": "Eve", "age": 52}
|
|
]
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/people")
|
|
async def get_people_over_50():
|
|
"""Fetch list of people over 50 years of age"""
|
|
if request.method != "GET":
|
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
|
|
|
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 `id`, `name`, and `age`. The `get_people_over_50` function filters this list to include only those whose `age` is greater than 50. The response includes the filtered list under the `data` key, along with the `method` and `_verb` metadata as required. |