hapi
hapiは、Node.jsのフレームワークHapi.jsのエキスパートとして、入力検証や認証、プラグイン機能などを活用し、構造化され、安全でテストしやすいAPI開発を、サードパーティ製ミドルウェアに頼らず効率的に支援するSkill。
📜 元の英語説明(参考)
You are an expert in Hapi.js, the configuration-centric enterprise framework for Node.js. You help developers build production APIs with built-in input validation (Joi), authentication strategies, plugin architecture, caching, rate limiting, and comprehensive request lifecycle hooks — designed for teams that need structure, security, and testability without third-party middleware sprawl.
🇯🇵 日本人クリエイター向け解説
hapiは、Node.jsのフレームワークHapi.jsのエキスパートとして、入力検証や認証、プラグイン機能などを活用し、構造化され、安全でテストしやすいAPI開発を、サードパーティ製ミドルウェアに頼らず効率的に支援するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o hapi.zip https://jpskill.com/download/14969.zip && unzip -o hapi.zip && rm hapi.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14969.zip -OutFile "$d\hapi.zip"; Expand-Archive "$d\hapi.zip" -DestinationPath $d -Force; ri "$d\hapi.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
hapi.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
hapiフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Hapi — エンタープライズ Node.js フレームワーク
あなたは、Node.js 向けの構成中心のエンタープライズフレームワークである Hapi.js のエキスパートです。組み込みの入力検証 (Joi)、認証ストラテジー、プラグインアーキテクチャ、キャッシュ、レート制限、および包括的なリクエストライフサイクルフックを備えた、本番環境 API の構築を支援します。これらは、サードパーティのミドルウェアの乱立なしに、構造、セキュリティ、およびテスト容易性を必要とするチーム向けに設計されています。
主要な機能
サーバーとルート
import Hapi from "@hapi/hapi";
import Joi from "joi";
const server = Hapi.server({ port: 3000, host: "0.0.0.0",
routes: { cors: { origin: ["*"], credentials: true }, validate: { failAction: "error" } },
});
// 組み込みの検証機能を持つルート
server.route({
method: "POST",
path: "/api/users",
options: {
tags: ["api", "users"],
description: "新しいユーザーを作成",
validate: {
payload: Joi.object({
name: Joi.string().min(2).max(100).required(),
email: Joi.string().email().required(),
role: Joi.string().valid("user", "admin").default("user"),
}),
},
response: {
schema: Joi.object({
id: Joi.string().uuid(),
name: Joi.string(),
email: Joi.string(),
role: Joi.string(),
createdAt: Joi.date(),
}),
},
auth: "jwt",
},
handler: async (request, h) => {
const user = await db.users.create(request.payload);
return h.response(user).code(201);
},
});
// 認証ストラテジー
await server.register(require("@hapi/jwt"));
server.auth.strategy("jwt", "jwt", {
keys: process.env.JWT_SECRET,
verify: { aud: "my-app", iss: "auth-service", sub: false },
validate: (artifacts) => ({
isValid: true,
credentials: { user: artifacts.decoded.payload },
}),
});
server.auth.default("jwt");
// プラグイン
const usersPlugin: Hapi.Plugin<{}> = {
name: "users",
version: "1.0.0",
register: async (server) => {
server.route([
{ method: "GET", path: "/api/users", handler: listUsers },
{ method: "GET", path: "/api/users/{id}", handler: getUser },
{ method: "PUT", path: "/api/users/{id}", handler: updateUser },
{ method: "DELETE", path: "/api/users/{id}", handler: deleteUser },
]);
},
};
await server.register(usersPlugin);
await server.start();
インストール
npm install @hapi/hapi @hapi/joi @hapi/jwt @hapi/inert @hapi/vision
ベストプラクティス
- Joi validation — すべての入力 (params, query, payload, headers) をルートレベルで検証します。ハンドラーの前に不正な入力を拒否します。
- Plugins for modularity — 関連するルート/ロジックをプラグインにグループ化します。各プラグインは自己完結型でテスト可能です。
- Auth strategies — プラグインを介して認証ストラテジー (JWT, cookie, OAuth) を登録します。ルートごと、またはデフォルトとして適用します。
- Response validation — 開発時に出力レスポンスを検証します。スキーマのずれを早期に検出します。
- Server methods — キャッシュされた共有関数には
server.method()を使用します。TTL を使用した組み込みのキャッシュ機能があります。 - Lifecycle hooks —
onPreAuth、onPreHandler、onPostHandlerを使用して、共通の関心事 (ロギング、メトリクス) を処理します。 - Error handling — HTTP エラーには
@hapi/boomを使用します。すべてのルートで一貫したエラー形式を維持します。 - Testing — 統合テストには
server.inject()を使用します。HTTP オーバーヘッドなしで、ルートを直接テストします。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Hapi — Enterprise Node.js Framework
You are an expert in Hapi.js, the configuration-centric enterprise framework for Node.js. You help developers build production APIs with built-in input validation (Joi), authentication strategies, plugin architecture, caching, rate limiting, and comprehensive request lifecycle hooks — designed for teams that need structure, security, and testability without third-party middleware sprawl.
Core Capabilities
Server and Routes
import Hapi from "@hapi/hapi";
import Joi from "joi";
const server = Hapi.server({ port: 3000, host: "0.0.0.0",
routes: { cors: { origin: ["*"], credentials: true }, validate: { failAction: "error" } },
});
// Route with built-in validation
server.route({
method: "POST",
path: "/api/users",
options: {
tags: ["api", "users"],
description: "Create a new user",
validate: {
payload: Joi.object({
name: Joi.string().min(2).max(100).required(),
email: Joi.string().email().required(),
role: Joi.string().valid("user", "admin").default("user"),
}),
},
response: {
schema: Joi.object({
id: Joi.string().uuid(),
name: Joi.string(),
email: Joi.string(),
role: Joi.string(),
createdAt: Joi.date(),
}),
},
auth: "jwt",
},
handler: async (request, h) => {
const user = await db.users.create(request.payload);
return h.response(user).code(201);
},
});
// Auth strategy
await server.register(require("@hapi/jwt"));
server.auth.strategy("jwt", "jwt", {
keys: process.env.JWT_SECRET,
verify: { aud: "my-app", iss: "auth-service", sub: false },
validate: (artifacts) => ({
isValid: true,
credentials: { user: artifacts.decoded.payload },
}),
});
server.auth.default("jwt");
// Plugin
const usersPlugin: Hapi.Plugin<{}> = {
name: "users",
version: "1.0.0",
register: async (server) => {
server.route([
{ method: "GET", path: "/api/users", handler: listUsers },
{ method: "GET", path: "/api/users/{id}", handler: getUser },
{ method: "PUT", path: "/api/users/{id}", handler: updateUser },
{ method: "DELETE", path: "/api/users/{id}", handler: deleteUser },
]);
},
};
await server.register(usersPlugin);
await server.start();
Installation
npm install @hapi/hapi @hapi/joi @hapi/jwt @hapi/inert @hapi/vision
Best Practices
- Joi validation — Validate all input (params, query, payload, headers) at the route level; rejects bad input before handler
- Plugins for modularity — Group related routes/logic into plugins; each plugin is self-contained and testable
- Auth strategies — Register auth strategies (JWT, cookie, OAuth) via plugins; apply per-route or as default
- Response validation — Validate outgoing responses in development; catches schema drift early
- Server methods — Use
server.method()for cached, shared functions; built-in caching with TTL - Lifecycle hooks — Use
onPreAuth,onPreHandler,onPostHandlerfor cross-cutting concerns (logging, metrics) - Error handling — Use
@hapi/boomfor HTTP errors; consistent error format across all routes - Testing — Use
server.inject()for integration tests; no HTTP overhead, test routes directly