pitfalls-express-api
Express API conventions and storage patterns. Use when building REST APIs, defining routes, or implementing storage interfaces. Triggers on: Express, router, API route, status code, storage interface.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o pitfalls-express-api.zip https://jpskill.com/download/17446.zip && unzip -o pitfalls-express-api.zip && rm pitfalls-express-api.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17446.zip -OutFile "$d\pitfalls-express-api.zip"; Expand-Archive "$d\pitfalls-express-api.zip" -DestinationPath $d -Force; ri "$d\pitfalls-express-api.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
pitfalls-express-api.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
pitfalls-express-apiフォルダができる - 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 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Express API の落とし穴
Express API におけるよくある落とし穴と正しいパターンについて説明します。
どのような時に使うか
- REST API ルートの構築
- ストレージインターフェースの実装
- HTTP ステータスコードの設定
- リクエストボディの検証
- Express API コードのレビュー
ワークフロー
ステップ 1: ルート構造の検証
ルートが REST の規約に従っているか確認します。
ステップ 2: ステータスコードの確認
各操作に対して正しいステータスコードが設定されていることを確認します。
ステップ 3: バリデーションの検証
入力検証ミドルウェアが適切に配置されていることを確認します。
ルート構造
// Public routes
GET /api/resource // List
GET /api/resource/:id // Get one
// Admin routes (with auth middleware)
POST /api/admin/resource // Create (201)
PATCH /api/admin/resource/:id // Update (200)
DELETE /api/admin/resource/:id // Delete (204)
// ✅ Always validate before storage
router.post('/', validateBody(schema), async (req, res) => {
const validated = req.body; // Already validated by middleware
});
ステータスコード
| 操作 | 成功 | Not Found | 無効 |
|---|---|---|---|
| GET | 200 | 404 | 400 |
| POST | 201 | - | 400 |
| PATCH | 200 | 404 | 400 |
| DELETE | 204 | 404 | - |
ストレージインターフェースのパターン
// ✅ Define interface for all storage operations
interface IStorage {
// Strategies
getStrategies(): Promise<Strategy[]>;
getStrategy(id: string): Promise<Strategy | undefined>;
createStrategy(data: NewStrategy): Promise<Strategy>;
updateStrategy(id: string, data: Partial<Strategy>): Promise<Strategy | undefined>;
deleteStrategy(id: string): Promise<boolean>;
}
// ✅ Implement for different backends
class DbStorage implements IStorage { ... } // PostgreSQL
class MemStorage implements IStorage { ... } // Testing
バックグラウンドジョブのパターン
// ✅ Cleanup on process exit
const intervals: NodeJS.Timeout[] = [];
function startJob(fn: () => void, ms: number) {
const id = setInterval(fn, ms);
intervals.push(id);
return id;
}
process.on('SIGTERM', () => {
intervals.forEach(clearInterval);
process.exit(0);
});
// ✅ Handle overlapping executions
let isRunning = false;
async function scanForOpportunities() {
if (isRunning) return;
isRunning = true;
try {
await scan();
} finally {
isRunning = false;
}
}
簡単なチェックリスト
- [ ] ルートが REST の規約に従っている
- [ ] 正しいステータスコードが返される
- [ ] すべてのエンドポイントで入力検証が行われる
- [ ] ストレージインターフェースの抽象化が使用される
- [ ] バックグラウンドジョブがクリーンアップを処理する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Express API Pitfalls
Common pitfalls and correct patterns for Express APIs.
When to Use
- Building REST API routes
- Implementing storage interfaces
- Setting HTTP status codes
- Validating request bodies
- Reviewing Express API code
Workflow
Step 1: Verify Route Structure
Check that routes follow REST conventions.
Step 2: Check Status Codes
Ensure correct status codes for each operation.
Step 3: Verify Validation
Confirm input validation middleware is in place.
Route Structure
// Public routes
GET /api/resource // List
GET /api/resource/:id // Get one
// Admin routes (with auth middleware)
POST /api/admin/resource // Create (201)
PATCH /api/admin/resource/:id // Update (200)
DELETE /api/admin/resource/:id // Delete (204)
// ✅ Always validate before storage
router.post('/', validateBody(schema), async (req, res) => {
const validated = req.body; // Already validated by middleware
});
Status Codes
| Operation | Success | Not Found | Invalid |
|---|---|---|---|
| GET | 200 | 404 | 400 |
| POST | 201 | - | 400 |
| PATCH | 200 | 404 | 400 |
| DELETE | 204 | 404 | - |
Storage Interface Pattern
// ✅ Define interface for all storage operations
interface IStorage {
// Strategies
getStrategies(): Promise<Strategy[]>;
getStrategy(id: string): Promise<Strategy | undefined>;
createStrategy(data: NewStrategy): Promise<Strategy>;
updateStrategy(id: string, data: Partial<Strategy>): Promise<Strategy | undefined>;
deleteStrategy(id: string): Promise<boolean>;
}
// ✅ Implement for different backends
class DbStorage implements IStorage { ... } // PostgreSQL
class MemStorage implements IStorage { ... } // Testing
Background Job Patterns
// ✅ Cleanup on process exit
const intervals: NodeJS.Timeout[] = [];
function startJob(fn: () => void, ms: number) {
const id = setInterval(fn, ms);
intervals.push(id);
return id;
}
process.on('SIGTERM', () => {
intervals.forEach(clearInterval);
process.exit(0);
});
// ✅ Handle overlapping executions
let isRunning = false;
async function scanForOpportunities() {
if (isRunning) return;
isRunning = true;
try {
await scan();
} finally {
isRunning = false;
}
}
Quick Checklist
- [ ] Routes follow REST conventions
- [ ] Correct status codes returned
- [ ] Input validation on all endpoints
- [ ] Storage interface abstraction used
- [ ] Background jobs handle cleanup