Step 13
Let's include a route to update a note.
| Update Note | |
|---|---|
| HTTP Method | PUT |
| API Endpoint | /api/notes/Id |
| Request Path Parameter | id |
| Request Query Parameter | |
| Request Body | JSON object (note attributes) |
| Response Body | JSON object (updated note) |
| Response Status | 200 |
Add the following route to index.js:
app.put("/api/notes/:id", async (req, res) => {
try {
const { id } = req.params;
const { title, text } = req.body;
const data = await notes.update(id, { title, text });
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 update a note that does not exist.
