Step 12

Let's include a route to delete a note.

Delete Note
HTTP MethodDELETE
API Endpoint/api/notes/:d
Request Path Parameterid
Request Query Parameter
Request Body
Response BodyJSON object (note)
Response Status200

Notice the path (endpoint) is similar to the GET request we had earlier for retrieving a note given its ID. By convention, we return the deleted note (with status code 200).

Add the following route to index.js:

app.delete("/api/notes/:id", async (req, res) => {
  try {
    const { id } = req.params;
    const data = await notes.delete(id);
    res.json({ data });
  } catch (err) {
    res.status(err.status).json({ message: err.message });
  }
});

Save the code, and then test this endpoint in Postman.

Also, test by requesting to delete a note that does not exist. (you can try to delete the same note again!)