- If we wanted to update, say, the first todo list, conventionally, PUT requires us to send the whole updated todo resource. Now let's create a PUT route:
{
method: 'PUT',
path: '/todo/{id}',
handler: (request, reply) => {
const index = request.params.id - 1;
// replace the whole resource with the new one
todoList[index] = request.payload;
return reply({ message: 'updated' });
}
}
Use the todo.js file for your reference at Code/Lesson-2/exercise-c1/routes.
- Now go to Insomnia and make the request. Remember to change the request type to PUT:
- You should see the following response:
{
"message": "updated"
}
- And when you do a GET on http://localhost:8000/todo/1, you should get the updated resource: