[英]Express GET Route not working
我已经使用Node和Express开发了REST API。 我正在尝试获取待办事项。 每个todo
列表项都包含一个id和text属性。 我想做的是GET
一条GET
路线,该路线可以通过将id作为route参数传递来获取特定的todo
列表项。 我尝试了几次尝试,但看不到我在做什么错。 我的代码是:
我的资料库
var mongoose = require('mongoose');
module.exports = mongoose.model('Todo', {
text : String,
done : Boolean
});
// get all todos list items
app.get('/api/todoo', function(req, res) {
// use mongoose to get all todos in the database
Todo.find(function(err, todos) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err)
res.send(err)
res.json(todos); // return all todos in JSON format
});
});
//Getting a todo list by ID
app.get('/api/todoo/:todo_id', function(req, res) {
Todo.find({id : req.params.todo_id},
function(err, todo) {
if (err)
res.send(err);
res.json(todos);
});
});
这仅仅是在您打算“要做”的地方出现“ todoo”的错字?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.