28 lines
909 B
Python
28 lines
909 B
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
people = [
|
|
{"name": "Alice", "age": 55},
|
|
{"name": "Bob", "age": 45},
|
|
{"name": "Charlie", "age": 60},
|
|
{"name": "David", "age": 35},
|
|
{"name": "Eve", "age": 52}
|
|
]
|
|
|
|
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 = [p for p in people if p["age"] > 50]
|
|
|
|
return {
|
|
"method": "GET",
|
|
"_verb": "get",
|
|
"people_over_50": 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 along with the expected metadata fields. It also includes a check to ensure the request method is GET, raising a 405 Method Not Allowed error if it is not. |