Update code in endpoints/users.get.py
This commit is contained in:
parent
dc9e22a28f
commit
ca1dd01706
36
endpoints/users.get.py
Normal file
36
endpoints/users.get.py
Normal file
@ -0,0 +1,36 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
users = [
|
||||
{
|
||||
"id": "1",
|
||||
"name": "John Doe",
|
||||
"email": "john@example.com"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"name": "Jane Smith",
|
||||
"email": "jane@example.com"
|
||||
}
|
||||
]
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/users")
|
||||
async def get_users():
|
||||
"""Fetch list of users"""
|
||||
return {
|
||||
"method": "GET",
|
||||
"_verb": "get",
|
||||
"users": users
|
||||
}
|
||||
```
|
||||
|
||||
To summarize:
|
||||
|
||||
- Imported necessary modules
|
||||
- Initialized an in-memory `users` list with example data
|
||||
- Created a `/users` endpoint using `@router.get` decorator
|
||||
- Returned a dict with `method`, `_verb` metadata and the `users` list
|
||||
- Followed the provided code structure and examples strictly
|
||||
|
||||
This endpoint will return the list of users with their names and emails when accessed via a GET request to `/users`.
|
Loading…
x
Reference in New Issue
Block a user