0% found this document useful (0 votes)
24 views2 pages

Assignment_ Build a RESTful API using Node (1)

Uploaded by

anshuraghav1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Assignment_ Build a RESTful API using Node (1)

Uploaded by

anshuraghav1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment: Build a RESTful API using Node.

js and Express (100 marks)

Objective:
Create a simple RESTful API for managing a list of users, testing concepts such as routing,
middleware, HTTP methods, status codes, error handling, and interaction with a data source.

Requirements:

1. Initialize a Node.js project: (5 marks)


○ Set up a new Node.js project.
○ Install Express.
2. Define a REST API with the following routes: (25 marks)
○ GET /users – Fetch the list of all users.
○ GET /users/:id – Fetch details of a specific user by ID.
○ POST /user – Add a new user.
○ PUT /user/:id – Update details of an existing user.
○ DELETE /user/:id – Delete a user by ID.
3. Sample User Object Structure:

{
"id": "1",
"firstName": "Anshika",
"lastName": "Agarwal",
"hobby": “Teaching”
}

4. Middleware: (30 marks)


○ Use middleware to log the details of each request (e.g., method, URL, status
code). (15 marks)
○ Implement validation middleware to check for required fields in the POST and PUT
routes. (15 marks)
5. Error handling: (10 marks)
○ Return appropriate HTTP status codes (e.g., 200, 404, 201, 400).
○ Handle errors (e.g., book not found, invalid input) and respond with meaningful
error messages.
6. Data source:
○ Store users data in-memory (using an array) for simplicity.

Submission Guidelines : (30 marks)

● Include clear comments in the code explaining the logic. (5 marks)


● Test your API using Postman or ThunderClient and include screenshots of the test
results. (25 marks)

Submit zip folder of your code and a document containing screenshots of your test results.

You might also like