简体   繁体   English

删除api请求以404错误响应

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

相关问题 向 API 执行“获取”请求时出现 404 错误 - 404 error when performing "Get" request to API VueJS、expressJS、axios 删除错误:请求失败,状态码为 404 - VueJS, expressJS, axios DELETE error: Request failed with status code 404 处理竞态条件:“护照注册”功能有效,但响应404错误 - Handle Race Condition: Passport SignUp function works but responds with 404 Error Github 页面对 three.js 画布和导入响应 404 错误 - Github pages responds with 404 error for three.js canvas and imports nodejs 和 twitter api 错误'错误:错误 Twitter 流式传输请求:404' - nodejs and twitter api error ' Error: Bad Twitter streaming request: 404 ' Ajax请求404错误 - 404 error with Ajax request jQuery Ajax删除404错误 - jquery ajax delete 404 error OAuth2:Discord API 总是响应 {“error”: “invalid_grant”} - OAuth2: Discord API always responds with {“error”: “invalid_grant”} 错误x-amzn-errortype:对API网关的DELETE请求上的InvalidSignatureException - Error x-amzn-errortype: InvalidSignatureException on DELETE request to API gateway 404错误获取错误请求快速API React.js,从api url获取sneakerId - 404 error GET bad request Rapid API React.js, get sneakerId from the api url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM