Get single item mysql

PHOTO EMBED

Wed Jun 01 2022 20:17:51 GMT+0000 (Coordinated Universal Time)

Saved by @zaccamp #javascript

// Get a single candidate
app.get('/api/candidate/:id', (req, res) => {
  const sql = `SELECT * FROM candidates WHERE id = ?`;
  const params = [req.params.id];

  db.query(sql, params, (err, row) => {
    if (err) {
      res.status(400).json({ error: err.message });
      return;
    }
    res.json({
      message: 'success',
      data: row
    });
  });
});
content_copyCOPY

https://courses.bootcampspot.com/courses/972/pages/12-dot-2-5-create-the-get-routes?module_item_id