Back to list
manhhuynh-designer

create-api-route

by manhhuynh-designer

0🍴 0📅 Jan 14, 2026

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 zod validation 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' or revalidate).
  • Environment: Use process.env.SUPABASE_SERVICE_ROLE_KEY for privileged backend operations.

Score

Total Score

40/100

Based on repository quality metrics

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

Reviews

💬

Reviews coming soon