Node.js Backend Assignment (1)
Node.js Backend Assignment (1)
Task Description
You will design a simple Node.js web server/application, having a set of REST endpoints, and using
MongoDB to store the details.
Dummy data APIs for your use are available at JSON Placeholder (https://jsonplaceholder.typicode.com/).
1. MongoDB
2. REST API
3. Typescript
Note: Only allowed to use the dependencies mentioned in the below package.json
{
"name": "node_assignment",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"typescript": "^5.0.2"
},
"dependencies": {
"mongodb": "^5.1.0"
}
}
GET /load Loads 10 users into DB, user data should be fetched from
JSON Placeholder along with users' posts, comments &
store the details in appropriate collection, should always
return empty response - with code 200 on success, else
an appropriate error code.
GET /users/:userId Get the specific user with userId from DB and return user
data including users post & comment for posts in
JSON format. See the user data format below.
PUT /users Put a new user into the DB, and the data is sent to the
server as the request body of this API, which should return
an appropriate error code if the resource already exists;
See the data format below.
Certain details (like the response for some endpoints) are deliberately left empty for you to design
according to best REST practices. Few things for you to think about
● Error code and response if a particular resource doesn't exist when using GET/DELETE
● Error code if POST body has a different userId field that the one it tries to update. Should it even
have a userId in the POST body?
● link header in response of POST/PUT
● Schema for users/posts/comments
Data format
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
},
"posts": [
{
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae
ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"comments": [
{
"id": 1,
"name": "id labore ex et quam laborum",
"email": "[email protected]",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo
necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"id": 2,
"name": "quo vero reiciendis velit similique earum",
"email": "[email protected]",
"body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod
ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
}
]
},
{
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat
blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi
nulla",
"comments": [
{
"id": 3,
"name": "et fugit eligendi deleniti quidem qui sint nihil autem",
"email": "[email protected]",
"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\naccusamus fugiat
dicta\nvoluptatem rerum ut voluptate autem\nvoluptatem repellendus aspernatur dolorem in"
},
{
"id": 4,
"name": "repellat consequatur praesentium vel minus molestias voluptatum",
"email": "[email protected]",
"body": "maiores sed dolores similique labore et inventore et\nquasi temporibus esse sunt id
et\neos voluptatem aliquam\naliquid ratione corporis molestiae mollitia quia et magnam dolor"
}
]
}
]
}
Submission Guidelines
● Please do not upload to any public source code repository like GitHub
● Please zip up your code and upload it to your Google Drive and share its link with us