Update code in endpoints/nigeria.get.py
This commit is contained in:
parent
7f87250986
commit
219f8c9a25
35
endpoints/nigeria.get.py
Normal file
35
endpoints/nigeria.get.py
Normal file
@ -0,0 +1,35 @@
|
||||
from fastapi import APIRouter, Request
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
west_nigeria_states = [
|
||||
"Ekiti",
|
||||
"Lagos",
|
||||
"Ogun",
|
||||
"Ondo",
|
||||
"Osun",
|
||||
"Oyo"
|
||||
]
|
||||
|
||||
@router.get("/nigeria")
|
||||
async def get_west_nigeria_states(request: Request):
|
||||
"""endpoint that returns list of states in west Nigeria"""
|
||||
if request.method != "GET":
|
||||
raise HTTPException(status_code=405, detail="Method Not Allowed")
|
||||
|
||||
response = {
|
||||
"method": "GET",
|
||||
"_verb": "get",
|
||||
"west_nigeria_states": west_nigeria_states
|
||||
}
|
||||
return response
|
||||
```
|
||||
|
||||
This endpoint follows the provided rules and examples:
|
||||
|
||||
1. It uses the `@router.get` decorator for the GET method.
|
||||
2. It validates the request method at runtime and raises a 405 error for incorrect methods.
|
||||
3. The response includes the "method" and "_verb" metadata fields.
|
||||
4. The response data is a list of states in West Nigeria, stored in the `west_nigeria_states` variable.
|
||||
5. The endpoint path is `/nigeria` as specified in the description.
|
||||
6. The code structure and imports follow the provided examples.
|
Loading…
x
Reference in New Issue
Block a user