From f53b347b95766e8e50b8724c34076f7bcc5e0af6 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 17:44:22 +0100 Subject: [PATCH] Update code in endpoints/logout.post.py --- endpoints/logout.post.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/endpoints/logout.post.py b/endpoints/logout.post.py index 816aaa7..ae67185 100644 --- a/endpoints/logout.post.py +++ b/endpoints/logout.post.py @@ -4,27 +4,23 @@ laptops = [ {"name": "MacBook Pro"}, {"name": "Dell XPS"}, {"name": "Lenovo ThinkPad"}, - {"name": "HP Spectre"}, - {"name": "Asus ZenBook"} + {"name": "HP Spectre"} ] router = APIRouter() @router.post("/logout") async def logout(): - """Returns list of laptop names""" + """endpoints that returns list of laptops names""" if request.method != "POST": - raise HTTPException(status_code=405, detail="Method Not Allowed") + raise HTTPException(status_code=405, detail={ + "message": "Method Not Allowed", + "method": "POST", + "_verb": "post" + }) return { "method": "POST", "_verb": "post", "laptops": [laptop["name"] for laptop in laptops] - } -``` - -This code defines a FastAPI endpoint using the `@router.post` decorator with the path `/logout`. The endpoint returns a list of laptop names stored in the `laptops` list. - -The response includes the HTTP method ("POST"), a method metadata field ("_verb": "post"), and the list of laptop names extracted from the `laptops` list. - -If the request method is not POST, it raises an HTTPException with a 405 Method Not Allowed status code. \ No newline at end of file + } \ No newline at end of file