admin管理员组文章数量:1418060
Hello I am trying to put the type value in my mongodb database using rest api. However, it shows an error saying cannot put (404 not found).
app.js
app.put('api/types/:_id', function(req,res){
var id = req.params._id;
var type = req.body;
Type.updateType(id, type, {}, function(err, type){
if(err){
throw err;
}
res.json(type);
});
});
type.js
module.exports.updateType = function(id, type, options, callback){
var query = {_id: id};
var update = {
name: type.name,
description: type.description,
category: type.category
}
Task.findOneAndUpdate(query,update, options, callback);
}
Hello I am trying to put the type value in my mongodb database using rest api. However, it shows an error saying cannot put (404 not found).
app.js
app.put('api/types/:_id', function(req,res){
var id = req.params._id;
var type = req.body;
Type.updateType(id, type, {}, function(err, type){
if(err){
throw err;
}
res.json(type);
});
});
type.js
module.exports.updateType = function(id, type, options, callback){
var query = {_id: id};
var update = {
name: type.name,
description: type.description,
category: type.category
}
Task.findOneAndUpdate(query,update, options, callback);
}
Share
Improve this question
asked May 30, 2017 at 18:50
Ankur ChavdaAnkur Chavda
1736 silver badges17 bronze badges
0
3 Answers
Reset to default 6Use '/api/types/:_id'
rather than 'api/types/:_id'
One more issue which causes the mentioned error:
Check if there is any typo mistake in the URL which you are trying to access.
In my case, I tried accessing
"/api/users/udpate/:id"
instead of
"/api/users/update/:id"
I have entered udpate instead of update.So express will not be able to find the route which causes this error.
Two solutions can be of this issue:
Can be a typo in endpoints.
Instead of this
"uesr/:userId"
Check for this
"/user/:userId"
Can be a slash missing in starting.
Instead of this
"user/:userId"
Add this slash in starting
"/user/:userId"
本文标签: javascriptCannot put error in rest api using node jsStack Overflow
版权声明:本文标题:javascript - Cannot put error in rest api using node js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745257914a2650212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论