38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
users = [
|
|
{
|
|
"id": "1",
|
|
"username": "user1",
|
|
"email": "user1@example.com",
|
|
"country": "USA"
|
|
},
|
|
{
|
|
"id": "2",
|
|
"username": "user2",
|
|
"email": "user2@example.com",
|
|
"country": "Canada"
|
|
}
|
|
]
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/users")
|
|
async def get_users():
|
|
"""Fetch list of users"""
|
|
return {
|
|
"method": "GET",
|
|
"_verb": "get",
|
|
"users": users
|
|
}
|
|
```
|
|
|
|
This endpoint adheres to the provided rules and examples:
|
|
|
|
1. It uses the `@router.get` decorator for the GET method.
|
|
2. The endpoint path is `/users`.
|
|
3. It returns a dictionary with the required keys: `"method"`, `"_verb"`, and `"users"`.
|
|
4. The `"users"` value is the list of user dictionaries.
|
|
5. Each user dictionary contains the keys `"id"`, `"username"`, `"email"`, and `"country"`.
|
|
|
|
Note: The user data is stored in an in-memory list called `users`. In a real application, this data would typically come from a database or other persistent storage. |