Update code in endpoints/people.get.py
This commit is contained in:
parent
4f64878316
commit
a21f62dbc9
@ -4,8 +4,8 @@ people = [
|
||||
{"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"}
|
||||
{"name": "Alice Williams", "age": 51, "country": "USA"},
|
||||
{"name": "Charlie Brown", "age": 48, "country": "UK"},
|
||||
]
|
||||
|
||||
router = APIRouter()
|
||||
@ -27,9 +27,23 @@ async def get_people_over_50():
|
||||
|
||||
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.
|
||||
- Uses the `@router.get` decorator for the `/people` endpoint
|
||||
- Validates the request method is GET, raising 405 Method Not Allowed if not
|
||||
- Filters the `people` list to include only those with `age` over 50
|
||||
- Returns a response with the required structure:
|
||||
- `"method": "GET"`
|
||||
- `"_verb": "get"`
|
||||
- `"data"` containing the filtered list of people over 50
|
||||
|
||||
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.
|
||||
The response data will be:
|
||||
|
||||
```json
|
||||
{
|
||||
"method": "GET",
|
||||
"_verb": "get",
|
||||
"data": [
|
||||
{"name": "John Doe", "age": 55, "country": "UK"},
|
||||
{"name": "Bob Johnson", "age": 62, "country": "UK"},
|
||||
{"name": "Alice Williams", "age": 51, "country": "USA"}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user