![](/img/trans.png)
[英]get method not displaying the data on browser and put showing error on postman
[英]Put and delete method is showing 404 in postman
0 我一直在努力思考为什么我的 PUT 和 DELETE 请求不起作用。 它返回 404 未找到响应。 我的 POST 和 GET 都工作正常。
我用铬 postman
app.put('api/courses/:id', (req, res) => {
const course = courses.find(c => c.id === parseInt(req.params.id));
if (!course) return res.status(404).send('This course with the given id was not found');
const { error } = validateCourse(req.body);
if (error)
return res.status(400).send(error.details[0].message);
course.name = req.body.name;
res.send(course);
});
app.delete('api/courses/:id', (req, res) => {
const course = courses.find(c => c.id === parseInt(req.params.id));
if (!course) return res.status(404).send('this course with the given ID is not valid');
const index = courses.indexOf(course);
courses.splice(index, 1)
res.send(course);
})
function validateCourse(course) {
const schema = {
name: Joi.string().min(3).required()
};
return Joi.validate(course, schema);
}
我正在尝试在 Node.js 中创建一个简单的 api。http 方法不起作用
添加前导/
到路由定义:
app.put('/api/courses/:id', ...);
服务器上没有相对路由之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.