diff --git a/endpoints/open.post.py b/endpoints/open.post.py index f70f597..8cd6f1b 100644 --- a/endpoints/open.post.py +++ b/endpoints/open.post.py @@ -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. \ No newline at end of file +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. \ No newline at end of file