31 lines
1.7 KiB
Python
31 lines
1.7 KiB
Python
from fastapi import APIRouter, HTTPException
|
||
|
||
router = APIRouter()
|
||
|
||
states = [
|
||
"Adana", "Adıyaman", "Afyonkarahisar", "Ağrı", "Amasya", "Ankara", "Antalya",
|
||
"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")
|
||
async def get_states(request):
|
||
if request.method != "POST":
|
||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||
|
||
return {
|
||
"method": "POST",
|
||
"_verb": "post",
|
||
"states": states
|
||
}
|
||
```
|
||
|
||
This endpoint follows the provided requirements and returns a list of states in Turkey when a POST request is made to the "/turkey" path. The states are stored in a list at the top of the file. The endpoint checks if the request method is POST, and if not, it raises an HTTPException with a 405 Method Not Allowed status code. If the method is POST, it returns a dictionary containing the method, a "_verb" key with the value "post", and the list of states. |