Update code in endpoints/logout.post.py
This commit is contained in:
parent
831fb37fa7
commit
f53b347b95
@ -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.
|
Loading…
x
Reference in New Issue
Block a user