Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 1.03 KB

README.md

File metadata and controls

51 lines (36 loc) · 1.03 KB

NOTE

Note: This library is no longer needed since hapi17. This feature has been included as standard since hapi 17. You can use this plugin up to version 16 hapijs.

See the link below.

hapijs/hapi#3429

hapi-es7-async-handler

async handler support for hapijs apps

npm version

You can use this plugin to add async handler function to your hapi projects.

requiements

You need es7 supported javascript development environment or use Typescript

Usage

Example:

const server = new Hapi.server()

const plugins = [
  ...
  {
    register: require('hapi-es7-async-handler'),
  },
  ...
];

server.register(plugins, (err) => {
  ...
})
server.route({
  path: '/',
  method: 'get',
  handler: async (request, reply) => {
    ...
    const result = await yourAsyncJob(); // the async job might be returning Promise object
    reply(result);
  }
});