2016-02-13 102 views
0

我一直在敲我的头最后4个小时试图找出为什么我的DELETE请求不起作用。它返回一个404找不到的响应。我的POST,PUT和GET都正常工作。DELETE API请求响应404错误

我使用Chrome的邮差做请求和我的URL格式是:

DELETE http://localhost:3000/api/products/568c39bfba6030c90c36a061

这里是我的代码。

Server.js:

var express = require('express'); 


var mongoose = require('mongoose'); 

var bodyParser =require('body-parser'); 


mongoose.connect('mongodb://127.0.0.1:27017/test'); 

var app = express(); 
app.use(bodyParser.urlencoded({ extend: true})); 
app.use(bodyParser.json()); 

app.use('/api', require('./routes/api')); 

app.listen(3000); 
console.log('API is running on port 3000'); 

Api.js:

var express = require('express'); 

var router = express.Router(); 


var Product = require('../models/product'); 


console.log(Product); 


Product.methods(['get', 'post', 'put',' delete']); 

Product.register(router, '/products'); 

module.exports = router; 

Product.js

var restful = require('node-restful'); 

var mongoose = restful.mongoose; 



var productSchema = new mongoose.Schema({ 

    name: String, 
    sku: String, 
    price: Number 
}); 

module.exports = restful.model('Products', productSchema); 

回答

2

你在你的删除方法名称空间(' delete')。

+1

Bro你是男人!我不知道我是如何错过的。非常感谢! –