← スキル一覧に戻る

create-api-route
by manhhuynh-designer
⭐ 0🍴 0📅 2026年1月14日
SKILL.md
name: Create API Route description: Generate robust, secure Next.js 16 App Router API endpoints with validation, auth checks, and strict server-side enforcement.
Create API Route
This skill guides you in creating secure and reliable API endpoints for Next.js 16.
1. Security First Principles (Next.js 16)
import 'server-only': MUST be at the top of the file to prevent accidental client-side usage.- Authentication: EVERY route must check for authentication/authorization before processing data.
- Validation: Strict
zodvalidation is mandatory. - Data Leakage: Never return raw error objects or sensitive fields to the client.
2. Core Structure
- File:
app/api/{route}/route.ts - Handlers: Named exports
GET,POST,PUT,DELETE.
3. Requirements
A. Validation (Zod)
You MUST use zod to validate incoming request bodies. Enforce max lengths on strings.
import { z } from 'zod';
const Schema = z.object({
field: z.string().max(100)
});
B. Authorization
Explicitly check permissions at the start of the function.
// Example: Check for admin secret or session
if (!authorized) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
C. Error Handling
- Log full errors to console (server-side).
- Return generic error messages to client to avoid exposing stack traces or DB schema.
4. Best Practices
- Cache Control: For GET routes in Next.js 16, explicitly set caching strategy if needed (
export const dynamic = 'force-dynamic'orrevalidate). - Environment: Use
process.env.SUPABASE_SERVICE_ROLE_KEYfor privileged backend operations.
スコア
総合スコア
40/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です