-
Task Objective : Setting up of mongo DB connection in a Node.Js server as well as performance of CRUD operations
-
Task Description: Create a Node.js server using any framework of choice (optional) and appropriate folder structure (routes, controllers, models, etc.) which will perform the following functions:
- Add a Todo task to a Todo collection
- Update a particular Todo task
- Delete Todo task
- Retrieve all Todo tasks (pagination optional)
Each Todo document should contain at least the following fields: _id, title, description, timestamp.
You can use either a local mongoDB instance or a hosted one on any provider of choice.
Push your code to GitHub and submit your accessible GitHub Link.
clone this branch
git clone https://github.com/kralconomoh/simple_Todolist_api.git
run the following command
yarn
yarn start
after running the yarn start command you should see the following in your terminal / shell
[nodemon] starting `node index.js`
Mongodb Connected
Server Listening on port 3000
send a post request to this api endpoint
http://localhost:3000/todos/
with a request body like this
{
"name": "Go for a walk",
"description": "Go For a walk with family at the tafawa balewa square",
}
send a get request to this api endpoint
http://localhost:3000/todos/todo/6235c4b6eafb61d762520936
response payload
{
"_id": "6235c4b6eafb61d762520936",
"name": "task 2",
"description": "lorem ipsum soms sjahsgas lehg awehd asssbe jdiifk",
"createdAt": "2022-03-19T11:55:34.557Z",
"updatedAt": "2022-03-19T11:55:34.557Z",
"__v": 0
}
send a post request to this api endpoint
http://localhost:3000/todos/6235b6911f74e43c9be32cb9
with a request body like this.
- Note the id property
{
"name": "Go for a walk",
"description": "Go For a walk with family at the tafawa balewa square"
}
send a delete request to this api endpoint
http://localhost:3000/todos/6235c4b6eafb61d762520936
response payload
{ message:'task deleted successfully' }
send a get request to this api endpoint
http://localhost:3000/todos/all
response payload
[
{
"_id": "6235b6611f74e43c9be32cb7",
"name": "Go for a walk",
"description": "Go For a walk with family at the tafawa balewa square",
"done": false,
"createdAt": "2022-03-19T10:54:25.099Z",
"updatedAt": "2022-03-19T10:54:25.099Z",
"__v": 0
}
]
Thanks for reading, that is all Bye :)