From b9c8bc184aa4f4fb2b6388fb3f1be5c9b2d0230e Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Sun, 23 Mar 2025 14:29:45 +0100 Subject: [PATCH] Update code in endpoints/tenants.post.py --- endpoints/tenants.post.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/endpoints/tenants.post.py b/endpoints/tenants.post.py index 476716d..ac14a35 100644 --- a/endpoints/tenants.post.py +++ b/endpoints/tenants.post.py @@ -3,8 +3,16 @@ from fastapi import APIRouter, HTTPException router = APIRouter() towns = [ - "Memphis", "Nashville", "Knoxville", "Chattanooga", "Clarksville", - "Murfreesboro", "Franklin", "Jackson", "Johnson City", "Bartlett" + "Memphis", + "Nashville", + "Knoxville", + "Chattanooga", + "Clarksville", + "Murfreesboro", + "Franklin", + "Jackson", + "Johnson City", + "Bartlett" ] @router.post("/tenants") @@ -17,13 +25,4 @@ async def get_tennessee_towns(): "method": "POST", "_verb": "post", "towns": towns - } -``` - -This code defines a FastAPI endpoint `/tenants` that accepts POST requests and returns a list of towns in Tennessee. The list of towns is stored in the `towns` variable at the top of the file. - -The endpoint function `get_tennessee_towns` first checks if the request method is POST using `if request.method != "POST"`. If the method is not POST, it raises an HTTPException with a 405 Method Not Allowed status code. - -If the method is POST, it returns a dictionary with three keys: `"method"` (the HTTP method used), `"_verb"` (a metadata field indicating the verb is "post"), and `"towns"` (the list of towns in Tennessee). - -Note that this code follows the provided rules and examples, including strict method adherence, response format, error handling, data storage, and code structure. \ No newline at end of file + } \ No newline at end of file