The goal of this assignment is to help you understand how a RESTful API works on the server-side using Node.js and Express. You will implement a microservice that allows users to be created, retrieved, updated, and deleted. The user data will be stored in memory (no database required).
Instead of forking, you will create a new repository using this template.
Important You will need NodeJS for this assignment. Be sure to install it if you have not already.
- Go to the original assignment repository on GitHub https://github.com/njit-prof-bill/microservice-api-js-template.
- Click the "Use this template" button (green button at the top of the page).
- Enter a name for your new repository (e.g.,
rest-api-assignment
). - Make sure the new repository is public unless instructed otherwise.
- Click "Create repository from template".
- Clone your new repository to your device.
- Run
npm install
in your project folder. - Implement the API by following the specifications below. Use JavaScript on NodeJS.
- Test your code; when done push your changes. Be sure you have merged to main.
- β GitHub Actions is already enabled, and your tests will run automatically when you push changes.
- Post the URL to your repository on Canvas to submit your work.
Your task is to implement the following API endpoints in src/index.js
:
{
"name": "John Doe",
"email": "john@example.com"
}
{
"id": "a1b2c3d4",
"name": "John Doe",
"email": "john@example.com"
}
- The
id
must be a unique string (e.g., useuuid
). - Returns
400 Bad Request
ifname
oremail
is missing.
GET /users/a1b2c3d4
{
"id": "a1b2c3d4",
"name": "John Doe",
"email": "john@example.com"
}
- Returns
404 Not Found
if the user ID does not exist.
{
"name": "John Updated",
"email": "john.updated@example.com"
}
{
"id": "a1b2c3d4",
"name": "John Updated",
"email": "john.updated@example.com"
}
- Returns
404 Not Found
if the user ID does not exist. - Returns
400 Bad Request
ifname
oremail
is missing.
DELETE /users/a1b2c3d4
- If the user is found and deleted, no response body is returned.
- Returns
404 Not Found
if the user ID does not exist.
- Use an in-memory array to store users.
- Follow RESTful conventions for HTTP methods and status codes.
- Handle errors properly (
400
,404
, etc.). - Ensure all API responses are structured correctly as shown above.
Use Postman, cURL, or any HTTP client to test your API.
curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d '{"name":"Alice","email":"alice@example.com"}'
- The repository includes automated tests using Jest and Supertest.
- Run the tests with:
npm test
- Ensure all tests pass before submitting your assignment.
π‘ GitHub Actions & Hidden Tests
- Your repository is configured with GitHub Actions to automatically test your code when you push changes.
- Hidden test cases will only run when your code is submitted (pushed to GitHub).
- Locally, you will only see public tests. If your submission fails hidden tests, you will need to debug based on test logs.
- Ensure your final implementation is pushed to the
main
branch of your repository. - Submit your GitHub repository URL via the designated submission form.
Your repository should include:
β
All required API endpoints
β
Passing public tests (npm test
runs locally)
β
Clean, well-structured code
Criteria | Points | Description |
---|---|---|
β POST /users works correctly | 1 point | API successfully creates users and returns correct responses. |
β GET /users/:id works correctly | 1 point | Retrieves a user by ID and returns correct responses. |
β PUT /users/:id works correctly | 1 point | Updates user details correctly and handles errors properly. |
β DELETE /users/:id works correctly | 1 point | Successfully deletes users and returns correct responses. |
β Error handling & correct HTTP status codes | 1 point | Returns proper status codes (400 , 404 ) when required. |
- Partial credit is possible if an endpoint works but has minor issues.
- If an endpoint does not function at all, the student will receive zero points for that endpoint.
- Tests must pass on GitHub Actions for points to be awarded.
- Follow good coding practices (descriptive variable names, proper indentation, and clear structure).
- API should use correct HTTP methods and status codes.
- Your implementation must not modify the test files (
user.test.js
and.github/workflows/test.yml
). - You are allowed to add files and folders if needed.
π Good luck! π―