← スキル一覧に戻る

new-api-route
by AppleLamps
⭐ 0🍴 0📅 2026年1月7日
SKILL.md
name: new-api-route description: Scaffold new Next.js API routes with proper patterns. Use when user mentions "create endpoint", "new API route", "add route", or "API for".
New API Route
Create API routes following project conventions for Next.js App Router.
Instructions
-
Determine route path and HTTP methods needed
-
Create route file at
src/app/api/<path>/route.ts -
Use this template:
import { NextResponse } from 'next/server'; import { sql } from '@/lib/db'; export const dynamic = 'force-dynamic'; export async function GET(request: Request) { try { const { searchParams } = new URL(request.url); const limit = parseInt(searchParams.get('limit') || '10', 10); const result = await sql` SELECT * FROM table_name ORDER BY created_at DESC LIMIT ${limit} `; return NextResponse.json({ data: result }); } catch (error) { console.error('Error in GET /api/<path>:', error); return NextResponse.json( { error: 'Failed to fetch data' }, { status: 500 } ); } } export async function POST(request: Request) { try { const body = await request.json(); // Validate required fields if (!body.requiredField) { return NextResponse.json( { error: 'Missing required field' }, { status: 400 } ); } const result = await sql` INSERT INTO table_name (field) VALUES (${body.field}) RETURNING * `; return NextResponse.json({ data: result[0] }, { status: 201 }); } catch (error) { console.error('Error in POST /api/<path>:', error); return NextResponse.json( { error: 'Failed to create' }, { status: 500 } ); } } -
For admin routes, place under
src/app/api/admin/ -
Add types to
src/lib/db.tsif needed
Project Patterns
- Always use
force-dynamicfor database routes - Use parameterized queries (template literals with sql``)
- Return consistent JSON shape:
{ data, error, success } - Log errors with route context:
console.error('Error in GET /api/x:', error)
Examples
- "Create an API route for user profiles"
- "Add endpoint to get article by slug"
- "New admin route to clear cache"
Guardrails
- Use parameterized queries to prevent SQL injection
- Add TODO comment for auth:
// TODO: Add authentication in production - Validate all user input before database operations
- Never expose internal error messages to clients
スコア
総合スコア
50/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
レビュー
💬
レビュー機能は近日公開予定です