38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
Here's the FastAPI endpoint that returns a list of users from the `users` table, following the provided requirements and examples:
|
|
|
|
```python
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
users = [
|
|
{
|
|
"id": "1",
|
|
"username": "user1",
|
|
"email": "user1@example.com",
|
|
"password": "password1",
|
|
"disabled": False
|
|
},
|
|
{
|
|
"id": "2",
|
|
"username": "user2",
|
|
"email": "user2@example.com",
|
|
"password": "password2",
|
|
"disabled": True
|
|
}
|
|
]
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/table")
|
|
async def get_users():
|
|
"""endpoint that retuns list of users in my table"""
|
|
if request.method != "GET":
|
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
|
|
|
return {
|
|
"method": "GET",
|
|
"_verb": "get",
|
|
"users": users
|
|
}
|
|
```
|
|
|
|
This endpoint defines a `GET` route at `/table` that returns a list of users stored in the `users` list. It includes the required response structure with the `method`, `_verb`, and `users` fields. If the request method is not `GET`, it raises a `405 Method Not Allowed` error. |