[英]DELETE api request responds with 404 error
I have been banging my head the last 4 hours trying to figure why my DELETE request does not work. 最近4个小时,我一直在想办法弄清楚为什么我的DELETE请求不起作用。 It returns a 404 not found response.
它返回404 not found响应。 My POST, PUT, and GET all work fine.
我的POST,PUT和GET都可以正常工作。
I am using Chrome's Postman to do the requests and my url format is: 我正在使用Chrome的Postman进行请求,我的网址格式为:
DELETE http://localhost:3000/api/products/568c39bfba6030c90c36a061 删除http:// localhost:3000 / api / products / 568c39bfba6030c90c36a061
Here is my code. 这是我的代码。
Server.js : 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: 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 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);
删除方法名称中有一个空格( ' delete'
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.