Update code in endpoints/open.post.py
This commit is contained in:
parent
d156ebd3cb
commit
686d9a9ccf
@ -1,15 +1,26 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
towns = [
|
||||
"Yaounde", "Douala", "Bafoussam", "Bamenda", "Garoua",
|
||||
"Maroua", "Ngaoundere", "Bertoua", "Ebolowa", "Buea"
|
||||
"Douala",
|
||||
"Yaoundé",
|
||||
"Garoua",
|
||||
"Bamenda",
|
||||
"Bafoussam",
|
||||
"Nkongsamba",
|
||||
"Maroua",
|
||||
"Ngaoundéré",
|
||||
"Kumba",
|
||||
"Edéa"
|
||||
]
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/open")
|
||||
async def list_towns():
|
||||
async def get_towns():
|
||||
"""Returns list of towns in Cameroun"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
@ -17,4 +28,8 @@ async def list_towns():
|
||||
}
|
||||
```
|
||||
|
||||
This endpoint adheres to the POST method requirement and returns a list of towns in Cameroun. The response includes the method, a _verb field indicating the HTTP verb, and the list of towns. It follows the provided code structure and examples.
|
||||
This code defines a list of towns in Cameroun, then creates a FastAPI router with a single POST endpoint at `/open`. When this endpoint is called with a POST request, it returns the list of towns along with the request method metadata.
|
||||
|
||||
If the request is made with any HTTP method other than POST, it will raise a 405 Method Not Allowed error.
|
||||
|
||||
The response format adheres strictly to the provided examples, including the `method`, `_verb`, and nested data structure under the `towns` key.
|
Loading…
x
Reference in New Issue
Block a user