This service manages users for a company.
Rather than connecting to an external data source, the service manipulates an in-memory collection, meaning the collection is reset when the server restarts.
# Prerequisites (if not already installed)
brew install nvm
nvm install 14
npm i -g nodemon
# Switch to Node 14
nvm use
# Install dependencies
npm i
# Run
nodemon
The application will run at http://localhost:3000 (the port can be changed in index.js
).
Note: nodemon
will restart the server for every code change. If you don't want this, you can run node index.js
instead; you will have to restart the server manually to propagate any code changes.
{
"username": "string",
"firstName": "string",
"lastName": "string"
}
{
"firstName": "string",
"lastName": "string"
}
{
"error": "string"
}
The following endpoints are included in the Postman collection (see postman.json
). If you don't have Postman installed, you can download it at postman.com/downloads. To import a collection, select Import in the top-left corner, then select Upload Files and choose postman.json
in this directory. You can also use the cURL commands in curls.sh
.
- Health check
- Get all users
- Get a specific user by username
- Create a new user
- Update an existing user by username or create a new one with a specific username
- Delete a specific user by username
- Endpoint:
GET /health
- Status:
200 OK
- Description: The health check always returns a
200 OK
response.
- Description: The health check always returns a
- Endpoint:
GET /users
- Status:
200 OK
- Description: The users are successfully returned (with
[]
if there are no users). - Body:
User[]
- Header:
Content-Type
gives the format of the response (application/json
).
- Description: The users are successfully returned (with
- Endpoint:
GET /users/{username}
username
is the username of the user.
- Status:
200 OK
- Description: The user with the specified user is returned.
- Body:
User
- Header:
Content-Type
gives the format of the response (application/json
).
- Status:
404 Not Found
- Description: No user with the specified username was found.
- Endpoint:
POST /users
- Body:
User
- Status:
201 Created
- Description: The user was successfully created.
- Header:
Location
gives the address of the new user.
- Status:
400 Bad Request
- Description: Something is wrong with the request body.
- Body:
Error
- Header:
Content-Type
gives the format of the response (application/json
).
- Endpoint:
PUT /users/{username}
username
is the username of the user.
- Body:
UserUpdate
- Status:
204 No Content
- Description: The user was successfully updated.
- Status:
201 Created
- Description: The user was successfully created.
- Header:
Location
gives the address of the new user.
- Status:
400 Bad Request
- Description: Something is wrong with the request body.
- Body:
Error
- Header:
Content-Type
gives the format of the response (application/json
).
- Endpoint:
DELETE /users/{username}
username
is the username of the user.
- Status:
204 No Content
- Description: The user was successfully deleted.
- Status:
404 Not Found
- Description: No user with the specified username was found.