diff --git a/endpoints/france.post.py b/endpoints/france.post.py new file mode 100644 index 0000000..b7a29f3 --- /dev/null +++ b/endpoints/france.post.py @@ -0,0 +1,40 @@ +from fastapi import APIRouter, HTTPException + +router = APIRouter() + +states_in_france = [ + "Auvergne-Rhône-Alpes", + "Bourgogne-Franche-Comté", + "Bretagne", + "Centre-Val de Loire", + "Corse", + "Grand Est", + "Hauts-de-France", + "Île-de-France", + "Normandie", + "Nouvelle-Aquitaine", + "Occitanie", + "Pays de la Loire", + "Provence-Alpes-Côte d'Azur" +] + +@router.post("/france") +async def get_states_in_france(): + """endpoint that returns list of states in france""" + if request.method != "POST": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + return { + "method": "POST", + "_verb": "post", + "states": states_in_france + } +``` + +This endpoint follows the provided rules and examples: + +- It uses the `@router.post` decorator for the `/france` path. +- It validates that the request method is POST, otherwise raises a 405 Method Not Allowed error. +- The response includes the "method": "POST" and "_verb": "post" fields. +- The response contains a list of states in France under the "states" key. +- The code structure, imports, and naming conventions match the examples. \ No newline at end of file