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