diff --git a/endpoints/users.get.py b/endpoints/users.get.py index 52e3be5..b3e30c5 100644 --- a/endpoints/users.get.py +++ b/endpoints/users.get.py @@ -3,17 +3,13 @@ from fastapi import APIRouter, HTTPException users = [ { "id": "1", - "username": "user1", - "email": "user1@example.com", - "country": "USA", - "state": "California" + "name": "John Doe", + "country": "Nigeria" }, { "id": "2", - "username": "user2", - "email": "user2@example.com", - "country": "Canada", - "state": "Ontario" + "name": "Jane Smith", + "country": "South Africa" } ] @@ -21,15 +17,14 @@ router = APIRouter() @router.get("/users") async def get_users(): - """Fetch list of users""" - if request.method != "GET": - raise HTTPException(status_code=405, detail="Method Not Allowed") - - return { + """Fetches list of users""" + response = { "method": "GET", "_verb": "get", "users": users } -``` - -This endpoint fetches a list of users from the in-memory `users` list. It checks if the request method is GET, and if not, raises a 405 Method Not Allowed error. The response includes the method, a "_verb" metadata field, and the list of user objects containing id, username, email, country, and state. \ No newline at end of file + + if request.method != "GET": + raise HTTPException(status_code=405, detail="Method Not Allowed") + + return response \ No newline at end of file