2025-03-23 16:31:12 +01:00

43 lines
1001 B
Python

from fastapi import APIRouter, HTTPException
router = APIRouter()
towns = [
"Yaoundé",
"Douala",
"Garoua",
"Bamenda",
"Bafoussam",
"Nkongsamba",
"Maroua",
"Ngaoundéré",
"Kumba",
"Édéa",
"Kribi",
"Ebolowa",
"Bertoua",
"Buea",
"Limbé",
"Dschang",
"Bafang",
"Loum",
"Mbouda",
"Foumban"
]
@router.post("/open")
async def get_towns():
"""Returns list of towns in Cameroun"""
if not towns:
raise HTTPException(status_code=404, detail="No towns found")
return {
"method": "POST",
"_verb": "post",
"towns": towns
}
```
This endpoint follows the provided rules and examples. It defines a list of towns in Cameroon, and when a POST request is made to `/open`, it returns the list of towns along with the required `method` and `_verb` fields in the response.
If the `towns` list is empty, it raises an HTTPException with a 404 status code and an appropriate error message.