mcpField
H
hapi

hapi

github.com/damusixDevelopment6239 installsUpdated 1w ago
Repository

About hapi

A Hapi development reference skill for developers building server applications with Hapi. It covers server setup, routes, authentication, validation, lifecycle hooks, plugins, and TypeScript patterns.

Key features

  1. 01Server setup and plugins
  2. 02Route handlers and validation
  3. 03Three-layer authentication
  4. 04Lifecycle and extension hooks
  5. 05TypeScript route and plugin patterns

Use cases

  1. 01Starting a Hapi server
  2. 02Defining validated routes
  3. 03Configuring route authentication
  4. 04Testing requests with server.inject()

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/damusix/skills --skill hapi

After installing, type/hapiin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

.tessl-plugin/
plugin.json
reference/auth/
basic.md
reference/file-serving/
directory-handler.md
file-handler.md
overview.md
reference/jwt-auth/
overview.md
token-api.md
validate.md
reference/lifecycle/
boom.md
bounce.md
methods.md
overview.md
request-object.md
response-marshal.md
response-object.md
response-toolkit.md
reference/plugins/
overview.md
reference/route/
auth.md
cache-cors.md
handler.md
misc.md
overview.md
payload.md
pre.md
response.md
security.md
validation.md
reference/server/
auth.md
cache.md
catbox-fs.md

Details

From the project README

Hapi

Quick Start

const server = Hapi.server({ port: 3000 });
server.route({ method: 'GET', path: '/', handler: () => 'ok' });
await server.start();

Critical Rules

  1. Compose with decorations & methods - Expose services via decorations and reusable logic via methods
  2. Follow the lifecycle - 24-step request flow; see lifecycle overview
  3. Auth is three layers - scheme → strategy → default; see server auth
  4. Validate at the route - Use joi schemas on params, query, payload, headers; see validation
  5. Type routes with Refs - Use ServerRoute<Refs> with ONLY the keys you need (Params, Query, Payload, etc.); omitted keys keep defaults. See route scaffold

Auth three-layer pattern:

server.auth.scheme('custom', schemeImpl);     // 1. scheme (how to authenticate)
server.auth.strategy('session', 'custom', options); // 2. strategy (configured instance)
server.auth.default('session');                // 3. default (apply to all routes)

Scheme authenticate MUST return h.authenticated() with both credentials AND artifacts:

return h.authenticated({
    credentials: { user: { id, name }, scope: ['user'] },
    artifacts: { token }       // always include artifacts for raw auth data
});

Route validation pattern:

server.route({
    method: 'POST',
    path: '/users',
    options: {
        validate: {
            payload: Joi.object({
                name: Joi.string().required(),
                email: Joi.string().email().required()
            })
        }
    },
    handler: (request) => request.payload
});

Workflow

  1. Create server - server overview for constructor options
  2. Register plugins - plugins and plugin structure
  3. Configure auth - auth schemes and route auth
  4. Verify auth - Test with server.inject() before defining protected routes; see network
  5. Define routes - route overview with handlers
  6. Add extensions - lifecycle hooks and pre-handlers

Key Patterns

TopicReference
Request/response objectsrequest, response
Response toolkit (h)toolkit
Sessions (yar)sessions
Caching & CORScache-cors, server cache, catbox-memory engine, catbox-fs engine, catbox-redis engine
Security headerssecurity
Payload parsingpayload
Decorations & methodsdecorations, methods
MIME types (mimos)mimos
Realms & plugin scopingrealm
Response marshallingmarshal pipeline
File serving (inert)overview, file handler, directory handler
Basic authenticationbasic auth
Error handling (Boom)boom errors
Error filtering (Bounce)bounce utility
WebSockets (nes)overview, subscriptions, client
SSE (sse)overview, api, subscriptions, session, replay
Startup & shutdownstartup lifecycle
Eventsevents
Testing (server.inject)network
TypeScript overviewtypescript
TypeScript auth typingauth-scheme, type-author
JWT authenticationjwt overview, validate function, token API
TypeScript pluginsplugin-scaffold
Views & templatesvision overview, engines, context & layouts

Comments

Markdown supported