Update code in endpoints/table.get.py
This commit is contained in:
parent
41fa047a57
commit
7ee9f97a3b
38
endpoints/table.get.py
Normal file
38
endpoints/table.get.py
Normal file
@ -0,0 +1,38 @@
|
||||
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.
|
Loading…
x
Reference in New Issue
Block a user