Step 8

Here is another GET request.

Read Notes (filter by author)
HTTP MethodGET
API Endpoint/api/notes
Request Path Parameter
Request Query Parameterauthor
Request Body
Response BodyJSON array of notes
Response Status200

For this one, we expect a client to use the same endpoint as before but optionally provide an author name as a query parameter. We can update the route we already have (/api/notes) to account for this scenario:

app.get("/api/notes", (req, res) => {
  const author = req.query.author;
  res.json(notes.readAll(author));
});

Save the code then head over to your browser and visit http://localhost:4567/api/notes?author=Author 2. You must receive a JSON array containing two sample notes, written by "Author 2".

Test this endpoint in Postman too.