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?
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?
Share Improve this question edited May 2, 2016 at 21:16 simon-p-r 3,7512 gold badges22 silver badges37 bronze badges asked May 2, 2016 at 14:18 parkerageeparkeragee 3231 gold badge3 silver badges14 bronze badges 1-
payload
is the request body, unless you're sending a request body through Postman,null
is the expected value. – Matt Harrison Commented May 2, 2016 at 16:38
1 Answer
Reset to default 7You 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'}