Update code in endpoints/france.post.py
This commit is contained in:
parent
f2282a3768
commit
33af6de413
@ -1,43 +1,21 @@
|
||||
Here's the FastAPI endpoint that returns a list of states in France:
|
||||
|
||||
```python
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
states = [
|
||||
"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",
|
||||
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_france(request):
|
||||
async def get_france_states():
|
||||
"""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
|
||||
"states": states_in_france
|
||||
}
|
||||
```
|
||||
|
||||
This endpoint follows the provided rules:
|
||||
|
||||
1. It uses the `@router.post` decorator for the `/france` path.
|
||||
2. It validates that the request method is POST, raising a 405 Method Not Allowed error otherwise.
|
||||
3. The response includes the "method": "POST" and "_verb": "post" fields.
|
||||
4. The response contains a list of states in France under the "states" key.
|
||||
|
||||
Note: The list of states is hardcoded in the `states` variable at the top of the file. In a real application, this data would likely come from a database or external API.
|
Loading…
x
Reference in New Issue
Block a user