From 7ee9f97a3b75b97ed07197c1edfd10031afe9733 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 08:20:17 +0100 Subject: [PATCH] Update code in endpoints/table.get.py --- endpoints/table.get.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 endpoints/table.get.py diff --git a/endpoints/table.get.py b/endpoints/table.get.py new file mode 100644 index 0000000..45c7fcc --- /dev/null +++ b/endpoints/table.get.py @@ -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. \ No newline at end of file