From 831fb37fa78187ce6d9211993c70c81bd3ddcbca Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 17:42:50 +0100 Subject: [PATCH] Update code in endpoints/logout.post.py --- endpoints/logout.post.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/endpoints/logout.post.py b/endpoints/logout.post.py index 0d8ffd1..816aaa7 100644 --- a/endpoints/logout.post.py +++ b/endpoints/logout.post.py @@ -1,18 +1,18 @@ from fastapi import APIRouter, HTTPException laptops = [ - {"name": "Dell XPS 13"}, - {"name": "MacBook Pro 16"}, - {"name": "Lenovo ThinkPad X1 Carbon"}, - {"name": "HP Spectre x360"}, - {"name": "Asus ZenBook Pro Duo"} + {"name": "MacBook Pro"}, + {"name": "Dell XPS"}, + {"name": "Lenovo ThinkPad"}, + {"name": "HP Spectre"}, + {"name": "Asus ZenBook"} ] router = APIRouter() @router.post("/logout") async def logout(): - """endpoints that returns list of laptops names""" + """Returns list of laptop names""" if request.method != "POST": raise HTTPException(status_code=405, detail="Method Not Allowed") @@ -20,4 +20,11 @@ async def logout(): "method": "POST", "_verb": "post", "laptops": [laptop["name"] for laptop in laptops] - } \ No newline at end of file + } +``` + +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