Update code in endpoints/turkey.post.py
This commit is contained in:
parent
7adbf7ba6e
commit
ebb778656f
41
endpoints/turkey.post.py
Normal file
41
endpoints/turkey.post.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
Here's a FastAPI endpoint that returns a list of states in Turkey:
|
||||||
|
|
||||||
|
```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: 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 specified requirements:
|
||||||
|
|
||||||
|
- 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