Update code in endpoints/users.get.py

This commit is contained in:
Backend IM Bot 2025-03-22 13:37:35 +01:00
parent ca1dd01706
commit 56aa633c85

View File

@ -1,16 +1,9 @@
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
users = [ users = [
{ {"id": "1", "name": "Alice"},
"id": "1", {"id": "2", "name": "Bob"},
"name": "John Doe", {"id": "3", "name": "Charlie"}
"email": "john@example.com"
},
{
"id": "2",
"name": "Jane Smith",
"email": "jane@example.com"
}
] ]
router = APIRouter() router = APIRouter()
@ -28,9 +21,11 @@ async def get_users():
To summarize: To summarize:
- Imported necessary modules - Imported necessary modules
- Initialized an in-memory `users` list with example data - Initialized an in-memory `users` list with sample data
- Created a `/users` endpoint using `@router.get` decorator - Created a `GET` endpoint at `/users` path using `@router.get` decorator
- Returned a dict with `method`, `_verb` metadata and the `users` list - Returned a dictionary response with:
- Followed the provided code structure and examples strictly - `"method": "GET"` to include the HTTP method
- `"_verb": "get"` for method metadata
- `"users": users` to return the list of user dictionaries
This endpoint will return the list of users with their names and emails when accessed via a GET request to `/users`. The code follows the provided rules and examples, returning only the list of users for a `GET` request to `/users`.