我正在创建一个rest api,删除请求没有被读取。这是代码
app.delete("/students:/id", async (req, res) => {
console.log("in delete")
try {
const _id = req.params.id
const delete_student = await Student.findOneAndDelete(_id)
console.log(req.params.id)
if(!req.params.id){
return res.status(400).send()
}
res.send(delete_student).status(200)
} catch (error) {
res.status(500).send(error)
}
})
这是响应
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot DELETE /62b93a487624a06ef8756439</pre>
</body>
</html>
路径应该声明为:
app.delete("/students/:id", async (req, res) => { ... })