diff --git a/endpoints/nigeria.get.py b/endpoints/nigeria.get.py new file mode 100644 index 0000000..dfa2266 --- /dev/null +++ b/endpoints/nigeria.get.py @@ -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. \ No newline at end of file