Update code in endpoints/france.post.py
This commit is contained in:
parent
3278e0e7ef
commit
1b4c30f7eb
40
endpoints/france.post.py
Normal file
40
endpoints/france.post.py
Normal file
@ -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 code defines a POST endpoint `/france` that returns a list of states in France. It follows the provided guidelines:
|
||||||
|
|
||||||
|
- Uses `@router.post` decorator for the endpoint
|
||||||
|
- Checks if the request method is POST, raising a 405 error if not
|
||||||
|
- Returns the list of states along with the required "method" and "_verb" fields in the response
|
||||||
|
|
||||||
|
The list of states is stored in the `states_in_france` variable at the top of the file.
|
Loading…
x
Reference in New Issue
Block a user