Hapi support for Node.js

Introduction

Hapi is an open-source framework for web applications. The most common use of Hapi is to build web services - see https://hapi.dev/external link for more information.

Objects

This extension creates the application and operation objects:

  • a ‘NodeJS Application’ object when the ‘Hapi.server’ API or a ‘Hapi.Server’ instance is found;
  • a ‘NodeJS Delete Operation’ object when the ‘route’ API of a server is found, and the method key is ‘DELETE’;
  • a ‘NodeJS Get Operation’ object when the ‘route’ API of a server is found, and the method key is ‘GET’;
  • a ‘NodeJS Post Operation’ object when the ‘route’ API of a server is found, and the method key is ‘POST’;
  • a ‘NodeJS Put Operation’ object when the ‘route’ API of a server is found, and the method key is ‘PUT’.
IconDescription
NodeJS Application
NodeJS Delete Operation
NodeJS Get Operation
NodeJS Post Operation
NodeJS Put Operation
Link TypeCaller typeCallee type
callLink
  • NodeJS Delete Operation
  • NodeJS Get Operation
  • NodeJS Post Operation
  • NodeJS Put Operation
  • JavaScript function
relyonLink
  • NodeJS Application
  • JavaScript Source Code

Example

Take the following codes:

const Hapi = require('@hapi/hapi');

const init = async () => {
    const server = Hapi.server({
        port: 3000,
        host: 'localhost'
    });

    server.route({
        method: 'GET',
        path: '/api',
        handler: (request, h) => {

            return 'Hello World!';
        }
    });

    await server.start();
};

In this example, a ‘NodeJS Application’ and a ‘NodeJS Get Operation’ objects are created. A ‘relyOn’ link is added between ‘index’ application and ‘index.js’ source code when ‘server’ API is found in ‘index.js’ file. A ‘call’ link is also created between ‘api/’ get operation and ‘handler’ function.