Step 12
Let's include a route to delete a note.
| Delete Note | |
|---|---|
| HTTP Method | DELETE |
| API Endpoint | /api/notes/:d |
| Request Path Parameter | id |
| Request Query Parameter | |
| Request Body | |
| Response Body | JSON object (note) |
| Response Status | 200 |
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!)
