DELETE api请求响应404错误

时间:2016-02-13 02:28:10

标签: javascript node.js mongodb api express

在过去的4个小时里,我一直在试图弄清楚为什么我的DELETE请求不起作用。它返回404未找到的响应。我的POST,PUT和GET一切正常。

我正在使用Chrome的邮递员来处理请求,我的网址格式为:

删除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); 

1 个答案:

答案 0 :(得分:2)

您的删除方法名称中有一个空格(' delete')。