Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Hapi.js POST handler returning an empty payload?

I have a Hapi route that accepts a POST call, but the request returns a null value for the payload.

server.route({
    method: ['POST', 'PUT'],
    path: '/create_note',
    handler: function (request, reply) {
        console.log(request.payload); // returns `null`
        return reply(request.payload);
    }
});

I'm using Postman to send a POST call to http://localhost:8000/create_note?name=test.

In the handler function, console.log(request.payload) returns null.

Am I doing something wrong?

like image 369
parkeragee Avatar asked Oct 17 '25 14:10

parkeragee


1 Answers

You are passing query string parameters with ?name=test, not the POST request payload.

You can access the query parameters by referencing request.query.

An HTTP request to http://localhost:8000/create_note?name=test will yield:

console.log(request.query); // {name: 'test'}
like image 124
Francesco Pezzella Avatar answered Oct 20 '25 05:10

Francesco Pezzella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!