eolas/Programming_Languages/NodeJS/REST_APIs/4_DELETE.md

20 lines
421 B
Markdown
Raw Normal View History

2023-02-15 17:40:55 +00:00
---
categories:
- Programming Languages
tags: [backend, node-js, REST, APIs]
---
# Creating a RESTful API: `DELETE` requests
```js
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);
});
```