diff --git a/endpoints/people.get.py b/endpoints/people.get.py index af8f8ab..dd64630 100644 --- a/endpoints/people.get.py +++ b/endpoints/people.get.py @@ -1,22 +1,22 @@ 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} + {"name": "John Doe", "age": 55, "country": "UK"}, + {"name": "Jane Smith", "age": 45, "country": "USA"}, + {"name": "Bob Johnson", "age": 62, "country": "UK"}, + {"name": "Alice Williams", "age": 38, "country": "USA"}, + {"name": "Charlie Brown", "age": 51, "country": "UK"} ] router = APIRouter() @router.get("/people") async def get_people_over_50(): - """Fetch list of people over 50 years of age""" + """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] + over_50 = [person for person in people if person["age"] > 50] return { "method": "GET", @@ -25,4 +25,11 @@ async def get_people_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. \ No newline at end of file +This endpoint follows the provided rules and examples: + +- It uses the `@router.get` decorator for the GET method. +- It checks if the request method is GET, and raises a 405 error if not. +- It filters the `people` list to include only those over 50 years of age. +- The response includes the "method", "_verb", and "data" (filtered list) fields. + +Note: The `people` list is pre-populated with sample data for demonstration purposes. In a real application, this data would typically come from a database or other data source. \ No newline at end of file