Delete Endpoint

So that users can remove memories that were accidentally added or that they no longer wish to have recorded, you add a DELETE endpoint:

service.delete('/memories/:id', (request, response) => {
// issue delete statement...
});

The ID of the memory is included as a parameter in the URL. You don't need any other data beyond the ID, so you complete ignore the body of the request.

SQL has a DELETE statement, but you don't want to permanently remove any memories. Instead, you issue a soft-delete. A soft-deleted message has its is_deleted field set to 1. It will not be returned by a GET request. You use an UPDATE statement to soft-delete memories:

service.delete('/memories/:id', (request, response) => {
const parameters = [parseInt(request.params.id)];

const query = 'UPDATE memory SET is_deleted = 1 WHERE id = ?';
connection.query(query, parameters, (error, result) => {
if (error) {
response.status(404);
response.json({
ok: false,
results: error.message,
});
} else {
response.json({
ok: true,
});
}
});
});

Try adding this endpoint to your service and restarting it. Because this is a DELETE request, you can't test it with your browser. Instead, run a command like this in your terminal:

curl --request DELETE \
http://example.com:5001/memories/8

Adjust the ID in the URL as needed to point to an existing memory. Try querying for all the memories on this month and day. Does the updated record appear in the results?