route.delete("/rest/todo/:todo_id",function(req,res){
console.log("data >> "+JSON.stringify(req.params));
ContTodo.remove(req,function(err,data){
if(err){
res.end(err);
}
res.json(data);
})
})
此路线无效
但在删除params之后它工作正常
route.delete("/rest/todo",function(req,res){
console.log("data >> "+JSON.stringify(req.params));
ContTodo.remove(req,function(err,data){
if(err){
res.end(err);
}
res.json(data);
})
})
工作正常。这里的路由出了什么问题 我被困在这里试试很长一段时间
server.js内容
var express = require("express");
var app = express();
var mongoose = require("mongoose");
var bodyParser = require("body-parser");
var methodOverride = require("method-override");
var morgan = require("morgan");
var toDo = require("./route/ToDo");
//######## Configuration
mongoose.connect("mongodb://127.0.0.1:27017/users");
app.use(express.static(__dirname+'/view'));
app.use(morgan("dev"));
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());
app.use(bodyParser.json({type:'application/vnd.api+json'}));
app.use(methodOverride());
//Routing
app.use('/',toDo);
//listen server startup
app.listen(8080,function(){
console.log('server is listning at'+'8080');
});
ToDo.js内容
var express = require("express");
var route = express.Router();
var ContTodo = require("../controller/ContTodo");
route.get("/rest/delete:",function(req,res){
console.log("data >> "+JSON.stringify(req.params));
ContTodo.remove(req,function(err,data){
if(err){
res.end(err);
}
res.json(data);
})
})
route.get("/rest/todo",function(req,res){
ContTodo.find(function(err,data){
if(err){
res.end("Something Wrong !!");
}
res.json(data);
})
});
route.post("/rest/todo",function(req,res){
ContTodo.create(req,function (err,data) {
if(err){
res.end("Something Wrong !!");
}
res.json(data)
})
});
module.exports = route;
请有人以某种方式解释差异,以便我能够理解网络的实际基础
答案 0 :(得分:0)
你正以错误的方式访问它。首先了解RequestParam
和PathVaraible
之间的区别。您需要致电您的服务127.0.0.1:8080/rest/todo/572323d661927ae23cd5ccb3