Update code in endpoints/open.post.py

This commit is contained in:
Backend IM Bot 2025-03-23 16:51:18 +01:00
parent e637ef2b0b
commit 8bac8cb2d0

View File

@ -3,21 +3,21 @@ from fastapi import APIRouter, HTTPException
router = APIRouter() router = APIRouter()
towns = [ towns = [
"Yaounde", "Yaoundé",
"Douala", "Douala",
"Bafoussam",
"Garoua", "Garoua",
"Maroua", "Bafoussam",
"Bamenda", "Bamenda",
"Ngaoundere", "Nkongsamba",
"Bertoua", "Maroua",
"Ebolowa", "Ngaoundéré",
"Kribi" "Kumba",
"Edéa"
] ]
@router.post("/open") @router.post("/open")
async def get_cameroon_towns(): async def get_towns():
"""endpoint that returns list of town in camerouns""" """Endpoint that returns list of towns in Cameroun"""
if request.method != "POST": if request.method != "POST":
raise HTTPException(status_code=405, detail="Method Not Allowed") raise HTTPException(status_code=405, detail="Method Not Allowed")
@ -26,3 +26,6 @@ async def get_cameroon_towns():
"_verb": "post", "_verb": "post",
"towns": towns "towns": towns
} }
```
This code defines a POST endpoint `/open` that returns a list of towns in Cameroun. It uses an in-memory list `towns` to store the town names. The endpoint checks if the request method is POST, and if not, it raises a 405 Method Not Allowed error. The response includes the method ("POST"), the method metadata ("_verb": "post"), and the list of towns.