From ebb778656f8b1777bdb60afd2efe298714e6a52b Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 08:56:37 +0100 Subject: [PATCH] Update code in endpoints/turkey.post.py --- endpoints/turkey.post.py | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 endpoints/turkey.post.py diff --git a/endpoints/turkey.post.py b/endpoints/turkey.post.py new file mode 100644 index 0000000..31f117f --- /dev/null +++ b/endpoints/turkey.post.py @@ -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. \ No newline at end of file