eolas/Programming_Languages/NodeJS/REST_APIs/4_DELETE.md
2022-08-28 10:37:22 +01:00

437 B

categories tags
Programming Languages
backend
node-js
REST
APIs

RESTful API with Node, Express and MongoDB: DELETE requests

router.delete('/:id', (req, res) => {
  const course = courses.find((c) => c.id === parseInt(req.params.id));
  if (!course) return res.status(404).send('A course with the given ID was not found');

  courses.indexOf(course);
  courses.splice(index, 1);
  res.send(course);
});