Testing Delete Todo Endpoint¶
To be able to test our delete enpoint, we will have to obtain id of an existing item from our database. We can do it by going to MongoDB Atlas, entering to our "Cluster0" and go to "Collections" tab.
After that, you can select "todos" collection and all todo items will be listed on the right side if there is any.
In order to delete an item, we will use value of _id
attribute.
You can see from the image above that we currently have just one item we added in the testing phase of adding a new todo item, so we will test deletion on that one.
Its id is61f3419038091d71e30e66df
.
Now, in Postman, we will create a new Request just like we did previousely by clicking "+" button.
We will set our request method to DELETE [1] and in the URL section we will add http://localhost:3001/todo/61f3419038091d71e30e66df [2].
You should replace id with the id of your object from the database.
We will now click "Send" button to send our request to backend.
After request is processed you should be able to see the response with status code 200 which means our item with provided it should be deleted.
To verify that, lets again go to our MongoDB Atlas and see if it is deleted.
Since we only had one item in our database, it is clear that deletion was successful.
Lets again save our Request in Postman so we can use it later if needed. You can repeat the same process as for "Add Todo Item" request. We will name it "Delete Todo Item" and hit "Save" button.
The only endpoint that is still not implemented and we will need it one that will toggle is_done
status of the specific item.
We will cover that in the next part.