Update code in endpoints/france.post.py
This commit is contained in:
parent
e513811f9c
commit
fc90bcba81
38
endpoints/france.post.py
Normal file
38
endpoints/france.post.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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.
|
Loading…
x
Reference in New Issue
Block a user