Update code in endpoints/open.post.py
This commit is contained in:
parent
57a142fb3d
commit
2d730b21a0
@ -1,34 +1,28 @@
|
||||
Here's a possible implementation of a FastAPI endpoint that returns a list of towns in Arizona:
|
||||
|
||||
```python
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
arizona_towns = [
|
||||
"Phoenix", "Tucson", "Mesa", "Chandler", "Glendale",
|
||||
"Scottsdale", "Gilbert", "Tempe", "Peoria", "Surprise"
|
||||
towns = [
|
||||
"Phoenix",
|
||||
"Tucson",
|
||||
"Mesa",
|
||||
"Chandler",
|
||||
"Glendale",
|
||||
"Scottsdale",
|
||||
"Gilbert",
|
||||
"Tempe",
|
||||
"Peoria",
|
||||
"Surprise"
|
||||
]
|
||||
|
||||
@router.post("/open", response_model=dict)
|
||||
async def list_arizona_towns(request: dict):
|
||||
@router.post("/open")
|
||||
async def get_arizona_towns():
|
||||
"""endpoint that returns list of town in arizona"""
|
||||
if request.method != "POST":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
return {
|
||||
"method": "POST",
|
||||
"_verb": "post",
|
||||
"towns": arizona_towns
|
||||
"towns": towns
|
||||
}
|
||||
```
|
||||
|
||||
This endpoint adheres to the following rules:
|
||||
|
||||
1. It uses the `@router.post` decorator for the `/open` endpoint path.
|
||||
2. It validates that the request method is POST, raising a 405 Method Not Allowed error otherwise.
|
||||
3. It returns a dictionary response with the following structure:
|
||||
- `"method": "POST"` (the HTTP method used)
|
||||
- `"_verb": "post"` (metadata about the HTTP verb)
|
||||
- `"towns": arizona_towns` (a list of town names in Arizona)
|
||||
|
||||
The `arizona_towns` list is defined at the top of the file as a Python list containing town names.
|
Loading…
x
Reference in New Issue
Block a user