[英]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.