This guide describes the users API backed by the local users.json file. It explains the endpoints, required data, and expected behavior so you can build your own requests.
-
Install dependencies (run this once from the repository root):
npm install -
Start the server:
npm start
The server runs at http://localhost:3000. Keep it running in a separate terminal while you work on your scripts.
Base URL: http://localhost:3000
All requests that send a body must use JSON and include the header:
- Content-Type:
application/json; charset=UTF-8
Note
In the PATH specifications below, :id indicates a path parameter that should be replaced with the actual user ID number.
- Method:
GET - Path:
/users/:id
Response: a single user object (without password) or the text User not found.
- Method:
GET - Path:
/users
Response: an array of users (without password).
- Method:
POST - Path:
/users - Body: JSON with the following fields:
name(string)email(string)password(string, required)role(string)active(boolean)department(string)
Example body:
{
"name": "Jane Smith",
"email": "[email protected]",
"password": "secret123",
"role": "user",
"active": true,
"department": "Engineering"
}
Response: the created user (without password) and a generated id.
- Method:
PUT - Path:
/users/:id - Body: JSON with the full user object (all fields you want to keep must be included).
Example body:
{
"name": "Alice Johnson",
"email": "[email protected]",
"password": "new-secret",
"role": "admin",
"active": true,
"department": "Engineering"
}
Response: the updated user (without password).
- Method:
PATCH - Path:
/users/:id - Body: JSON with only the fields you want to change.
Example body:
{
"email": "[email protected]"
}
Response: the updated user (without password).
- Method:
DELETE - Path:
/users/:id
Response: the text "User deleted successfully" on success.
- Passwords are never returned in API responses.
- The server hashes the
passwordyou send in POST, PUT, or PATCH requests.