简体   繁体   English

放入和删除方法在postman中显示404

[英]Put and delete method is showing 404 in postman

0 I have been banging my head the long hours trying to figure why my PUT and DELETE request does not work. 0 我一直在努力思考为什么我的 PUT 和 DELETE 请求不起作用。 It returns a 404 not found response.它返回 404 未找到响应。 My POST and GET all work fine.我的 POST 和 GET 都工作正常。

I use chrome postman我用铬 postman

app.put('api/courses/:id', (req, res) => {

    const course = courses.find(c => c.id === parseInt(req.params.id));
    if (!course) return res.status(404).send('This course with the given id was not found');

    const { error } = validateCourse(req.body);
    if (error) 
        return res.status(400).send(error.details[0].message);

    course.name = req.body.name;
    res.send(course);

});

app.delete('api/courses/:id', (req, res) => {
    const course = courses.find(c => c.id === parseInt(req.params.id));
    if (!course) return res.status(404).send('this course with the given ID is not valid');
  
    const index = courses.indexOf(course);
    courses.splice(index, 1)

    res.send(course);

})

function validateCourse(course) {
    const schema = {
        name: Joi.string().min(3).required()
    };

    return Joi.validate(course, schema);

}

I am trying to create a simple api in Node.js. The http method is not working我正在尝试在 Node.js 中创建一个简单的 api。http 方法不起作用

Add a leading / to the route definitions:添加前导/到路由定义:

app.put('/api/courses/:id', ...);

There is no such thing as relative routes on the server.服务器上没有相对路由之类的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取方法不在浏览器上显示数据并在 postman 上显示错误 - get method not displaying the data on browser and put showing error on postman 在前端使用 XMLHttpRequest 发送的 PUT、DELETE 会给出 404 响应,但在 postman 中工作得很好 - PUT, DELETE sent using XMLHttpRequest on frontend give 404 response, but in postman work just fine PUT 方法在前端不起作用,但在 Postman 中起作用 - PUT method is not working in front end but works in Postman 在 POSTMAN 上使用 PUT/POST 方法上传文件 - Upload a file with PUT/POST method on POSTMAN 在IIS 7.5服务器2008上获取404以进行PUT和DELETE请求 - Getting 404 for PUT and DELETE request on IIS 7.5 server 2008 为什么我的 PUT 和 DELETE 请求会出现 404 状态? - Why do I get a 404 status to my PUT and DELETE requests? ExpressJS对象PUT,DELETE没有方法'toLowerCase' - ExpressJS Object PUT,DELETE has no method 'toLowerCase' Angular $ resource方法PUT获取在服务器上找不到404 - Angular $resource method PUT gets 404 not found on server 将作品放入 Postman 而不是 AXIOS - Put works in Postman but not AXIOS 使用带有提取 json 的 DELETE 方法未找到错误 404 - Error 404 Not found using DELETE method with fetch json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM