jpskill.com
🛠️ 開発・MCP コミュニティ

koa

あなたはExpressチームが開発した軽量WebフレームワークKoaのエキスパートとして、非同期処理やミドルウェアを活用し、必要な機能だけを追加できるKoaの特性を活かして、APIやWebサービスの開発を効率的にサポートするSkill。

📜 元の英語説明(参考)

You are an expert in Koa, the minimalist web framework created by the Express team. You help developers build APIs and web services using Koa's async/await middleware stack, context object, and composable architecture — providing a lightweight foundation where you add only what you need through middleware, without bundled routing or templating.

🇯🇵 日本人クリエイター向け解説

一言でいうと

あなたはExpressチームが開発した軽量WebフレームワークKoaのエキスパートとして、非同期処理やミドルウェアを活用し、必要な機能だけを追加できるKoaの特性を活かして、APIやWebサービスの開発を効率的にサポートするSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o koa.zip https://jpskill.com/download/15043.zip && unzip -o koa.zip && rm koa.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15043.zip -OutFile "$d\koa.zip"; Expand-Archive "$d\koa.zip" -DestinationPath $d -Force; ri "$d\koa.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して koa.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → koa フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Koa — 次世代 Node.js Web フレームワーク

あなたは、Express チームによって作成されたミニマリストな Web フレームワークである Koa のエキスパートです。Koa の async/await ミドルウェアスタック、コンテキストオブジェクト、および構成可能なアーキテクチャを使用して、開発者が API および Web サービスを構築するのを支援します。バンドルされたルーティングやテンプレート機能なしに、必要なものだけをミドルウェアを通じて追加できる軽量な基盤を提供します。

主要な機能

アプリケーション

import Koa from "koa";
import Router from "@koa/router";
import bodyParser from "koa-bodyparser";
import cors from "@koa/cors";
import logger from "koa-logger";

const app = new Koa();
const router = new Router({ prefix: "/api" });

// エラー処理 (アップストリーム)
app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err: any) {
    ctx.status = err.status || 500;
    ctx.body = { error: err.message };
    ctx.app.emit("error", err, ctx);
  }
});

app.use(logger());
app.use(cors());
app.use(bodyParser());

// ルート
router.get("/users", async (ctx) => {
  const page = parseInt(ctx.query.page as string) || 1;
  const users = await db.users.findAll({ offset: (page - 1) * 20, limit: 20 });
  ctx.body = { data: users, page };
});

router.post("/users", async (ctx) => {
  const { name, email } = ctx.request.body as any;
  if (!name || !email) ctx.throw(400, "Name and email required");
  const user = await db.users.create({ name, email });
  ctx.status = 201;
  ctx.body = user;
});

router.get("/users/:id", async (ctx) => {
  const user = await db.users.findById(ctx.params.id);
  if (!user) ctx.throw(404, "User not found");
  ctx.body = user;
});

// 認証ミドルウェア
async function auth(ctx: Koa.Context, next: Koa.Next) {
  const token = ctx.headers.authorization?.replace("Bearer ", "");
  if (!token) ctx.throw(401, "Unauthorized");
  ctx.state.user = await verifyToken(token);
  await next();
}

router.get("/profile", auth, async (ctx) => {
  ctx.body = ctx.state.user;
});

app.use(router.routes()).use(router.allowedMethods());
app.listen(3000, () => console.log("Server on :3000"));

ミドルウェアの構成

// Koa ミドルウェアは、ダウンストリームに流れ、その後アップストリームに戻ります (オニオンモデル)
app.use(async (ctx, next) => {
  const start = Date.now();
  await next();                           // ダウンストリーム
  const ms = Date.now() - start;          // バックアップストリーム
  ctx.set("X-Response-Time", `${ms}ms`);
});

// 複数のミドルウェアを構成する
import compose from "koa-compose";
const adminMiddleware = compose([auth, roleCheck("admin"), auditLog]);
router.delete("/users/:id", adminMiddleware, deleteUser);

インストール

npm install koa @koa/router koa-bodyparser @koa/cors
npm install -D @types/koa @types/koa__router

ベストプラクティス

  1. どこでも Async/await — Koa は async 上に構築されています。コールバックや、Express のような next(err) パターンはありません。
  2. コンテキストオブジェクトctx はリクエストとレスポンスを組み合わせたものです。レスポンスには ctx.body、解析された入力には ctx.request.body を使用します。
  3. アップストリームでのエラー処理 — エラーをキャッチするミドルウェアを最初に配置します。これにより、すべてのダウンストリームミドルウェアからのエラーをキャッチできます。
  4. エラーには ctx.throw — 手動でステータス/ボディを設定する代わりに、ctx.throw(404, "Not found") を使用します。
  5. リクエストデータには ctx.state — 認証されたユーザー、リクエスト ID などを ctx.state に格納します。ミドルウェア間で共有されます。
  6. 再利用のための構成koa-compose を使用して、ルートグループのミドルウェアスタックをバンドルします。
  7. 設計によるミニマリズム — Koa には、組み込みのルーター、ボディパーサー、または静的ファイルがありません。必要なものだけを追加します。
  8. オニオンモデル — ミドルウェアはダウンストリームに流れ、その後アップストリームに戻ります。応答時間の追跡は、リクエスト全体を自然にラップします。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Koa — Next-Generation Node.js Web Framework

You are an expert in Koa, the minimalist web framework created by the Express team. You help developers build APIs and web services using Koa's async/await middleware stack, context object, and composable architecture — providing a lightweight foundation where you add only what you need through middleware, without bundled routing or templating.

Core Capabilities

Application

import Koa from "koa";
import Router from "@koa/router";
import bodyParser from "koa-bodyparser";
import cors from "@koa/cors";
import logger from "koa-logger";

const app = new Koa();
const router = new Router({ prefix: "/api" });

// Error handling (upstream)
app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err: any) {
    ctx.status = err.status || 500;
    ctx.body = { error: err.message };
    ctx.app.emit("error", err, ctx);
  }
});

app.use(logger());
app.use(cors());
app.use(bodyParser());

// Routes
router.get("/users", async (ctx) => {
  const page = parseInt(ctx.query.page as string) || 1;
  const users = await db.users.findAll({ offset: (page - 1) * 20, limit: 20 });
  ctx.body = { data: users, page };
});

router.post("/users", async (ctx) => {
  const { name, email } = ctx.request.body as any;
  if (!name || !email) ctx.throw(400, "Name and email required");
  const user = await db.users.create({ name, email });
  ctx.status = 201;
  ctx.body = user;
});

router.get("/users/:id", async (ctx) => {
  const user = await db.users.findById(ctx.params.id);
  if (!user) ctx.throw(404, "User not found");
  ctx.body = user;
});

// Auth middleware
async function auth(ctx: Koa.Context, next: Koa.Next) {
  const token = ctx.headers.authorization?.replace("Bearer ", "");
  if (!token) ctx.throw(401, "Unauthorized");
  ctx.state.user = await verifyToken(token);
  await next();
}

router.get("/profile", auth, async (ctx) => {
  ctx.body = ctx.state.user;
});

app.use(router.routes()).use(router.allowedMethods());
app.listen(3000, () => console.log("Server on :3000"));

Middleware Composition

// Koa middleware flows downstream then back upstream (onion model)
app.use(async (ctx, next) => {
  const start = Date.now();
  await next();                           // Downstream
  const ms = Date.now() - start;          // Back upstream
  ctx.set("X-Response-Time", `${ms}ms`);
});

// Compose multiple middleware
import compose from "koa-compose";
const adminMiddleware = compose([auth, roleCheck("admin"), auditLog]);
router.delete("/users/:id", adminMiddleware, deleteUser);

Installation

npm install koa @koa/router koa-bodyparser @koa/cors
npm install -D @types/koa @types/koa__router

Best Practices

  1. Async/await everywhere — Koa is built on async; no callbacks, no next(err) pattern like Express
  2. Context objectctx combines request and response; ctx.body for response, ctx.request.body for parsed input
  3. Error handling upstream — Put error-catching middleware first; it catches errors from all downstream middleware
  4. ctx.throw for errors — Use ctx.throw(404, "Not found") instead of manual status/body setting
  5. ctx.state for request data — Store auth user, request ID, etc. in ctx.state; shared across middleware
  6. Compose for reuse — Use koa-compose to bundle middleware stacks for route groups
  7. Minimalist by design — Koa has no built-in router, body parser, or static files; add only what you need
  8. Onion model — Middleware flows down then back up; response-time tracking wraps the entire request naturally