Skip to content

Hapi

September 29, 2023
February 16, 2015

hapi.js is a opinionated framework developed and used by Walmart which simplifies the task of writing an API backend.

GitHub Orgs:

It has several design principles in mind:

Why You Should Consider hapi – hueniverse 2018 sales pitch

Hapi v8 undergone a refactoring to better modularize the internals.
Hapi v17 supports async/await.

hapi — Get Your Server Up and Running
hapi — v17 Upgrade Guide (Your Move to async/await)
learn hapi Learning Path — on Future Studio

Single Page | Hapi With Typescript | Softcover.io
Using Typescript with hapi
Hapi and TypeScript— splitting routes into multiple files | by Paul Walker | JavaScript in Plain English

hapijs/makemehapi: Self guided workshops to teach you about hapi. 2020 v17
hapijs/university: Community learning experiment 2017 v17, no update
dwyl/learn-hapi 2018 v18, no update

hapi.js - API Reference
hapi/API.md at master · hapijs/hapi

Hapi vs Express: Comparing Node.js Web Frameworks 2017-12
Many Express plugins are out-of-maintenance and it's difficult to pick a high quality one from the vast choice.

Using hapi.js with Socket.io · Matt Harrison 2015
Developing RESTful APIs with Hapi 2017, v17
Build a Secure Node.js Application with JavaScript Async Await Using Hapi ― Scotch 2018, and Okta auth

Hapi Tutorial Series - YouTube 2021, WittCode
bradtraversy/hapiapp: Hapi.js crash course app 2020 v18, vision + handlebar for template,
Hapi.js Framework Crash Course - YouTube 2017 v16

Sample Projects

hapipal/hpal: hapi pal CLI
hapipal/boilerplate: A friendly, proven starting place for your next hapi plugin or deployment

JKHeadley/rest-hapi: 🚀 A RESTful API generator for Node.js 2020 v19
lynnaloo/mullet 2020 v19

Aqua - A website and user system starter
Frame - A user system API for Node.js

Authentication

Authentication - hapi.dev

  1. register a scheme (usually via plugin)
    server.auth.scheme(name, scheme) or server.register()
    when using plugin the scheme name is hardcoded
  2. create strategy based on the scheme (specify options and implements validation)
    server.auth.strategy(name, scheme, [options])
  3. apply strategy to routes
    server.auth.default(strategy) or options: { auth: 'simple' } on route

Passport's design is similar.

hapi.js - Plugins authentication
hapi.js - Plugins authorization

mozilla/hawk: HTTP Holder-Of-Key Authentication Scheme

Frame - A user system API for Node.js
franciscogouveia/hapi-rbac

hapijs/crumb: CSRF crumb generation and validation for hapi

Token

johnbrett/hapi-auth-bearer-token: Simple Bearer authentication scheme plugin for hapi, accepts token by Header, Cookie or Query parameter.

dwyl/hapi-auth-jwt2: Secure Hapi.js authentication plugin using JSON Web Tokens (JWT) in Headers, URL or Cookies
jwt - hapi.dev

now-ims/hapi-now-auth: Hapi token auth for bearer and jwt outdated
dwyl/hapi-auth-jwt2
Token based auth system using JWT in hapi.js - CronJ Blog
Auth in Hapi with JWT – Marcos Bérgamo – Medium
HapiJS Authentication - Secure Your API With JWT little bit outdated, includes user creation

hapijs/bell: Third-party login plugin for hapi

hapijs/hapi-auth-cookie
Authentication and Authorization with hapi. — Medium
hapi — Authentication and Remember Me Using Cookies

OAuth

hapi — Authenticate with GitHub And Remember the Login

scope

use scope to handle access control
javascript - Role based authentication in HapiJS - Stack Overflow
Harnessing the magic of Hapi scopes

hapi.js - 18.3.2 API Reference

plugins

hapi.js - Plugins
hapi pal - Home

// get plugin in request handler
const plugin = request.server.plugins["name"];

knownasilya/hapi-decorators: Decorators for HapiJS routes
hapijs/scooter: User-agent information plugin for hapi
hapijs/vision: Templates rendering support for hapi.js
wraithgar/electricfence better static file serving

antonsamper/hapi-cron: 🕰️ Cron jobs for internal hapi.js routes
hapipal/toys: The hapi utility toy chest

log

mcollina/hapi-pino: Hapi plugin for the Pino logger
https://github.com/pinojs/hapi-pino/issues/91#issuecomment-553318439 need to set getChildBindings: () => ({})

routes

glue - hapi.dev
node.js - How to store routes in separate files when using Hapi? - Stack Overflow
sitraka-hq/hapi-auto-route: Autoloads hapi routes

bleupen/halacious HAL/HATEOAS support
mdibaiee/hapi-sequelize-crud: Hapi plugin that automatically generates RESTful API for CRUD

futurestudio/hapi-rate-limitor: A hapi plugin for rate limiting. Simple and easy.
patova: simple throttling for hapi.js – A sea of code
yonjah/ralphi: Pure Node.js simple rate limiting server to prevent bruteforce attacks

pagination

fknop/hapi-pagination: Hapi plugin to handle "custom" pagination
Paginating your hapi api

router

felixheck/bissle: Minimalist HALicious pagination response toolkit interface for HapiJS

nlf/mudskipper define your resource and create RESTful routes

devinivy/loveboat: the hapi route config preprocessor
devinivy/loveboat-paths: support listing multiple paths in hapi route config

docs

rest-hapi · A RESTful API generator
JKHeadley/rest-hapi: 🚀 A RESTful API generator for Node.js

krakenjs/hapi-openapi: Build design-driven apis with OpenAPI (formerly swagger) 2.0 and hapi.

glennjones/hapi-swagger: A Swagger interface for HAPI
z0mt3c/hapi-swaggered: Yet another hapi plugin providing swagger compliant API specifications based on routes and joi schemas to be used with swagger-ui.
z0mt3c/hapi-swaggered-ui: An easy swagger-ui drop-in plugin for hapi (to be used with hapi-swaggered).
desirable-objects/hapi-ending: An endpoint documentation plugin for HapiJS

Server Push/WebSocket

mtharrison/susie: Server-sent events with hapi

hapipal/underdog: HTTP/2 server-push for hapi

hapijs/nes: WebSocket adapter plugin for hapi routes more complication, requires corresponding client
rse/hapi-plugin-websocket: HAPI plugin for seamless WebSocket integration

less active:
Caligone/hapio: A simple bridge plugin between HapiJS and SocketIO
sibartlett/hapi-io: Awesome socket.io plugin for hapi

Data Store Drivers

asilluron/hapi-mongoose: Hapi Plugin to handle Mongoose handshake and initial setup
maxnachlinger/hapi-level-db: HapiJS / LevelDB integration
fritzy/gatepost: Node.js module for binding postgres queries to models.
aduis/hapi-rabbit: rabbitMQ hapijs plugin
midnightcodr/hapi-redis2: another simple redis plugin for hapijs that supports multiple connections

Microservices

Introducing chairo, a hapi.js Microservices Plugin | hueniverse
hapijs/chairo

Seneca, a microservices toolkit for Node.js

Books

Developing a hapi Edge: A Rich Node.JS Framework for Apps and Services eBook
Getting Started with hapi.js -O'Reilly Media
Manning | hapi.js in Action

Tips and Tricks

Storing data in server.options.app/server.app

hapi.js - Server-side caching

request.log() in handler() to emit request event.
Register server.events.on('request') handler to log.

Error

hapijs/boom: HTTP-friendly error objects is your friend
see hapi/API.md at master · hapijs/hapi
hapi.dev - boom

To append custom data to error:

let error = Boom.badRequest("invalid query");
error.output.payload.custom = "additional error data";