Step 13

Let's include a route to update a note.

Update Note
HTTP MethodPUT
API Endpoint/api/notes/Id
Request Path Parameterid
Request Query Parameter
Request BodyJSON object (note attributes)
Response BodyJSON object (updated note)
Response Status200

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.