Step 9
Here is another GET request.
| Read Notes (filter by author) | |
|---|---|
| HTTP Method | GET |
| API Endpoint | /api/notes |
| Request Path Parameter | |
| Request Query Parameter | query |
| Request Body | |
| Response Body | JSON array of notes |
| Response Status | 200 |
For this one, we expect a client to use the same endpoint as before but optionally provide a search query parameter. We can update the route we already have (/api/notes) to account for this scenario:
app.get("/api/notes", async (req, res) => {
const { query } = req.query;
const data = await notes.readAll(query);
res.json({ data });
});
Save the code, and then test this endpoint in Postman.
