Autosave: 2023-02-15 17:40:55
This commit is contained in:
parent
ab1203f3ec
commit
3f2122643b
28 changed files with 19 additions and 19 deletions
|
@ -1,19 +0,0 @@
|
||||||
---
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
```
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
---
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
```
|
Loading…
Add table
Reference in a new issue