This document describes the REST API endpoints for managing users. The server runs on http://localhost:5002
.
- Endpoint:
GET /users
- Description: Fetches a list of all users.
- Response:
- Status:
200 OK
- Body: Array of user objects.
[ { "id": 1, "name": "Alice", "hoursWorked": 10 }, { "id": 2, "name": "Bob", "hoursWorked": 5 } ]
- Status:
- Endpoint:
GET /users/:id
- Description: Fetches a specific user by their ID.
- Path Parameter:
id
(integer) - The ID of the user. - Response:
- Status:
200 OK
- Body: User object.
{ "id": 1, "name": "Alice", "hoursWorked": 10 }
- Status:
404 Not Found
if the user does not exist.
- Status:
- Endpoint:
POST /users
- Description: Adds a new user to the list.
- Request Body:
- Required:
{ "name": "string" }
- Required:
- Response:
- Status:
201 Created
- Body: The newly created user object.
{ "id": 3, "name": "Charlie", "hoursWorked": 0 }
- Status:
400 Bad Request
if the name is missing or empty.
- Status:
- Endpoint:
PUT /users/:id
- Description: Updates a user's information.
- Path Parameter:
id
(integer) - The ID of the user. - Request Body:
- Optional:
{ "name": "string" }
- Optional:
- Response:
- Status:
200 OK
- Body: The updated user object.
{ "id": 1, "name": "Alice Updated", "hoursWorked": 15 }
- Status:
404 Not Found
if the user does not exist.
- Status:
- Endpoint:
PATCH /users/:id
- Description: Adds hours to a user's
hoursWorked
field. - Path Parameter:
id
(integer) - The ID of the user. - Request Body:
- Required:
{ "hoursToAdd": number }
- Required:
- Response:
- Status:
200 OK
- Body: The updated user object.
{ "id": 1, "name": "Alice", "hoursWorked": 20 }
- Status:
400 Bad Request
ifhoursToAdd
is invalid. - Status:
404 Not Found
if the user does not exist.
- Status:
- Endpoint:
DELETE /users/:id
- Description: Deletes a specific user by their ID.
- Path Parameter:
id
(integer) - The ID of the user. - Response:
- Status:
200 OK
- Body: The deleted user object.
{ "id": 1, "name": "Alice", "hoursWorked": 10 }
- Status:
404 Not Found
if the user does not exist.
- Status:
- Endpoint:
DELETE /users
- Description: Deletes all users from the list.
- Response:
- Status:
200 OK
- Body: An empty array.
[]
- Status:
{
"id": 1,
"name": "Alice",
"hoursWorked": 10
}
- The
id
field is auto-incremented for each new user. - All CORS requests from
localhost
are allowed.