31 lines
841 B
Python
31 lines
841 B
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
users = [
|
|
{"id": "1", "name": "Alice"},
|
|
{"id": "2", "name": "Bob"},
|
|
{"id": "3", "name": "Charlie"}
|
|
]
|
|
|
|
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 sample data
|
|
- Created a `GET` endpoint at `/users` path using `@router.get` decorator
|
|
- Returned a dictionary response with:
|
|
- `"method": "GET"` to include the HTTP method
|
|
- `"_verb": "get"` for method metadata
|
|
- `"users": users` to return the list of user dictionaries
|
|
|
|
The code follows the provided rules and examples, returning only the list of users for a `GET` request to `/users`. |