36 lines
857 B
Python
36 lines
857 B
Python
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`. |