diff --git a/endpoints/users.get.py b/endpoints/users.get.py index 9ffb5f0..eb61c38 100644 --- a/endpoints/users.get.py +++ b/endpoints/users.get.py @@ -1,9 +1,18 @@ from fastapi import APIRouter, HTTPException users = [ - {"id": "1", "name": "Alice"}, - {"id": "2", "name": "Bob"}, - {"id": "3", "name": "Charlie"} + { + "id": "user1", + "username": "alice", + "email": "alice@example.com", + "disabled": False + }, + { + "id": "user2", + "username": "bob", + "email": "bob@example.com", + "disabled": True + } ] router = APIRouter() @@ -11,6 +20,9 @@ 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 { "method": "GET", "_verb": "get", @@ -18,14 +30,10 @@ async def get_users(): } ``` -To summarize: +This endpoint follows the provided rules and examples: -- Imported necessary modules -- Initialized an in-memory `users` list with sample data -- Created a `GET` endpoint at `/users` path using `@router.get` decorator -- Returned a dictionary response with: - - `"method": "GET"` to include the HTTP method - - `"_verb": "get"` for method metadata - - `"users": users` to return the list of user dictionaries - -The code follows the provided rules and examples, returning only the list of users for a `GET` request to `/users`. \ No newline at end of file +- It uses the `@router.get` decorator for the GET method. +- It checks if the request method is GET and raises a 405 error if not. +- The response includes the "method" and "_verb" metadata fields. +- It returns a list of user objects from the in-memory `users` list. +- The structure and fields of the response match the provided examples. \ No newline at end of file