- When we want to delete a resource, we use the DELETE method. Let's create a DELETE route:
{ method: 'DELETE', path: '/todo/{id}', handler: (request, reply) => { const index = request.params.id - 1; delete todoList[index]; // replaces with `undefined` return reply({ message: 'deleted' }); },},
Use the exercise-c1 folder for your reference at Code/Lesson-2.
- Now go to Insomnia and test it—you should get this response:
- Now try accessing the previously deleted resources—you should get a 404 error. However, in our previous GET route (in Exercise 6: Getting a Specific Resource), we did not cater ...