node.js - How to parse a read stream in hapi? -
how can parse , validate readable stream payload sent http client within hapi server handler? handler code looks @ present
{ method: 'post', path: '/', handler: function (request, reply) { request.payload.pipe(process.stdout); return reply('success'); } }
short explanation: don't need parse it, that's automatic default. validate same way normal request.
by default, hapi buffer readable stream coming chunked-encoding transfer memory , attempt parse you depending on request content-type
header. handler run only once stream has ended. because of default options of payload
config setting.
server.route({ config: { payload: { output: 'data', // these default options parse: true // these default options } } method: 'post', path: '/', handler: function (request, reply) { console.log(request.payload); // object return reply('success'); } });
so if client sends json request, request.payload
javascript object, not stream. can validate normal object using joi.
Comments
Post a Comment