2025-03-23 09:26:09 +01:00

38 lines
1.1 KiB
Python

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", status_code=200)
async def get_states_in_france():
"""Returns list of states in France"""
if not states_in_france:
raise HTTPException(status_code=404, detail="No states found")
return {
"method": "POST",
"_verb": "post",
"states": states_in_france
}
```
This endpoint defines a list `states_in_france` containing the names of states in France. The `@router.post` decorator creates a POST endpoint at `/france` that returns this list in the response with the appropriate method metadata.
If the `states_in_france` list is empty, it raises an HTTPException with a 404 status code.
The response format matches the provided examples, including the `method`, `_verb`, and data payload fields.