Update code in endpoints/turkey.post.py
This commit is contained in:
parent
ebb778656f
commit
3278e0e7ef
@ -1,41 +1,22 @@
|
|||||||
Here's a FastAPI endpoint that returns a list of states in Turkey:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
states = [
|
states_in_turkey = [
|
||||||
"Adana", "Adıyaman", "Afyonkarahisar", "Ağrı", "Amasya", "Ankara", "Antalya",
|
"Adana", "Adıyaman", "Afyonkarahisar", "Ağrı", "Aksaray", "Amasya", "Ankara", "Antalya", "Ardahan", "Artvin", "Aydın", "Balıkesir", "Bartın", "Batman", "Bayburt", "Bilecik", "Bingöl", "Bitlis", "Bolu", "Burdur", "Bursa", "Çanakkale", "Çankırı", "Çorum", "Denizli", "Diyarbakır", "Düzce", "Edirne", "Elazığ", "Erzincan", "Erzurum", "Eskişehir", "Gaziantep", "Giresun", "Gümüşhane", "Hakkâri", "Hatay", "Iğdır", "Isparta", "İstanbul", "İzmir", "Kahramanmaraş", "Karabük", "Karaman", "Kars", "Kastamonu", "Kayseri", "Kilis", "Kırıkkale", "Kırklareli", "Kırşehir", "Kocaeli", "Konya", "Kütahya", "Malatya", "Manisa", "Mardin", "Mersin", "Muğla", "Muş", "Nevşehir", "Niğde", "Ordu", "Osmaniye", "Rize", "Sakarya", "Samsun", "Şanlıurfa", "Siirt", "Sinop", "Sivas", "Şırnak", "Tekirdağ", "Tokat", "Trabzon", "Tunceli", "Uşak", "Van", "Yalova", "Yozgat", "Zonguldak"
|
||||||
"Artvin", "Aydın", "Balıkesir", "Bilecik", "Bingöl", "Bitlis", "Bolu", "Burdur",
|
|
||||||
"Bursa", "Çanakkale", "Çankırı", "Çorum", "Denizli", "Diyarbakır", "Edirne",
|
|
||||||
"Elazığ", "Erzincan", "Erzurum", "Eskişehir", "Gaziantep", "Giresun", "Gümüşhane",
|
|
||||||
"Hakkâri", "Hatay", "Isparta", "Mersin", "İstanbul", "İzmir", "Kars", "Kastamonu",
|
|
||||||
"Kayseri", "Kırklareli", "Kırşehir", "Kocaeli", "Konya", "Kütahya", "Malatya",
|
|
||||||
"Manisa", "Kahramanmaraş", "Mardin", "Muğla", "Muş", "Nevşehir", "Niğde", "Ordu",
|
|
||||||
"Rize", "Sakarya", "Samsun", "Siirt", "Sinop", "Sivas", "Tekirdağ", "Tokat",
|
|
||||||
"Trabzon", "Tunceli", "Şanlıurfa", "Uşak", "Van", "Yozgat", "Zonguldak", "Aksaray",
|
|
||||||
"Bayburt", "Karaman", "Kırıkkale", "Batman", "Şırnak", "Bartın", "Ardahan", "Iğdır",
|
|
||||||
"Yalova", "Karabük", "Kilis", "Osmaniye", "Düzce"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@router.post("/turkey")
|
@router.post("/turkey")
|
||||||
async def get_states(request: Request):
|
async def get_states_in_turkey():
|
||||||
|
"""Returns list of states in Turkey"""
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"_verb": "post",
|
"_verb": "post",
|
||||||
"states": states
|
"states": states_in_turkey
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This endpoint follows the specified requirements:
|
This code defines a FastAPI endpoint `/turkey` that returns a list of states in Turkey when a POST request is made to that endpoint. It follows the provided guidelines for method adherence, response format, and error handling.
|
||||||
|
|
||||||
- It uses the `@router.post` decorator for the `/turkey` endpoint path.
|
|
||||||
- It validates that the request method is POST, raising a 405 error otherwise.
|
|
||||||
- The response includes the "method", "_verb", and a list of "states" in Turkey.
|
|
||||||
- It adheres to the provided code structure and imports.
|
|
||||||
|
|
||||||
Note that this endpoint uses a static list of states hardcoded in the code. In a real application, you would likely fetch the states from a database or external API.
|
|
Loading…
x
Reference in New Issue
Block a user