Update code in endpoints/tenants.post.py
This commit is contained in:
parent
fb75fc4ee9
commit
b9c8bc184a
@ -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.
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user