Hapi support for Node.js

Introduction

This page explains the support of the Hapi framework.

Server

For example, create a server - index.js:

const Hapi = require('hapi');

// Create Server
const server = new Hapi.Server();

This will give the following result:

Routes

For example, create a route for a server:

server.route([     
    {
        method: 'GET',
        path: '/api/directors/{id}',
        handler: api.directors.get,
        config: {
            tags: ['api'],
            description: 'Get one director by id',
            notes: 'Get one director by id',
            validate: {
                params: {
                    id: Joi.number().required()
                }
            },
            cors: {
                origin: ['*']
            }
        }
    }
];

This will give the following result: