mysql - Node.js Post 方法请求不起作用 {"statusCode":404 ,"error" :"Not Found" ,"message" :"Not Found"}

标签 mysql node.js rest npm hapi.js

我对 Node.js 相当陌生,我使用的是下面页面中的教程。

http://www.9lessons.info/2017/02/create-restful-api-nodejs-mysql.html

现在遇到的问题是 post 方法。当我调用 Get 方法以外的任何其他方法时,我收到此错误:

https://github.com/srinivastamada/NodeRestful/blob/master/server.js

server.route({
    method: 'POST',
    path: '/messages',

    handler: function (request, reply) {

        const uid = request.payload.uid;
        console.log(uid);

        connection.query('SELECT * FROM messages WHERE uid_fk = "' + uid + '"', function (error, results, fields) {
            if (error) throw error;
            console.log(results);
            reply(results);
        });
    },
    config: {
        validate: {
            payload: {
                uid: Joi.number().integer()
            }
        }

    }
});

最佳答案

首先您需要将数据插入消息表中。

然后点击来自 POSTMAN 的 post 请求。见下图。

enter image description here

关于mysql - Node.js Post 方法请求不起作用 {"statusCode":404 ,"error" :"Not Found" ,"message" :"Not Found"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46440451/

相关文章:

mysql - ON DUPLICATE KEY UPDATE - 添加到现有值

php - Doctrine 2 getResult() 需要很多时间

MySQL根据同一表中的一列中的条件合并属于同一ID的表中的行

javascript - 使用 cfs 有条件调整大小 :graphicsmagick

javascript - GraphQL 缺少名称

python - 如何将模型方法暴露给 django-rest-framework

java - 从 Resttemplate 调用时不支持请求方法 'PUT'

php错误内爆传递了无效的参数

javascript - OpenLayers map 未渲染

node.js - 我可以为 REST api 中的不同方法编写相同的路径名吗?