reqeuest body in hapijs code example

Example: reqeuest body in hapijs

'use strict';

const Hapi = require('hapi');

const server = new Hapi.Server();
server.connection({
    host: 'localhost',
    port: 8000
});

server.route({
    method: 'POST',
    path:'/',
    handler: function (request, reply) {
        console.log(request.payload);
        console.log(request.raw.req.headers);
        return reply('hello world');
    },
    config: {
        payload: {
            output: 'data',
            parse: false
        }
    }
});

server.start((err) => {
    if (err) throw err;
    console.log('Server running at:', server.info.uri);
});

Tags:

Misc Example