hapi.js – a node.js API helper

While browsing for new and exciting libraries, I have stumbled upon Hapi.

https://hapijs.com/

Hapi is a node.js framework aimed at building APIs for your applications. In my opinion, it could successfully be used for projects that don’t necessarily have much logic in their API or the logic is moved to the database (e.g. JSON generation with stored procedures).

It also has a lot of prebuilt plugins, including JWT authentication:

https://hapijs.com/plugins

And it looks fun and really-really easy to use:

'use strict';

const Hapi = require('hapi');

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

server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
        reply('Hello, world!');
    }
});

server.route({
    method: 'GET',
    path: '/{name}',
    handler: function (request, reply) {
        reply('Hello, ' + encodeURIComponent(request.params.name) + '!');
    }
});

server.start((err) => {

    if (err) {
        throw err;
    }
    console.log(`Server running at: ${server.info.uri}`);
});Code language: JavaScript (javascript)