api-route-scaffold

Create new Next.js API routes following project patterns. Use when user mentions "new endpoint", "add API", "create route", or "POST/GET handler".

16 stars

Best use case

api-route-scaffold is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create new Next.js API routes following project patterns. Use when user mentions "new endpoint", "add API", "create route", or "POST/GET handler".

Teams using api-route-scaffold should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/api-route-scaffold/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/api-route-scaffold/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/api-route-scaffold/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How api-route-scaffold Compares

Feature / Agentapi-route-scaffoldStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create new Next.js API routes following project patterns. Use when user mentions "new endpoint", "add API", "create route", or "POST/GET handler".

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Creating API Routes

This project uses Next.js 16 App Router with a consistent API pattern across all routes.

## Instructions

1. **Create route file**: `app/api/<endpoint-name>/route.ts`

2. **Use this template**:
```typescript
import { NextRequest, NextResponse } from 'next/server';

// CORS headers for cross-origin requests
const corsHeaders = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
};

export async function OPTIONS() {
  return NextResponse.json(null, { headers: corsHeaders });
}

export async function POST(req: NextRequest) {
  try {
    const { /* destructure fields */ } = await req.json();

    // Input validation
    if (!requiredField) {
      return NextResponse.json(
        { error: 'Field is required' },
        { status: 400, headers: corsHeaders }
      );
    }

    // Check required environment variables
    const apiKey = process.env.YOUR_API_KEY;
    if (!apiKey) {
      console.error('YOUR_API_KEY is not configured');
      return NextResponse.json(
        { error: 'YOUR_API_KEY is not configured' },
        { status: 500, headers: corsHeaders }
      );
    }

    // Business logic here
    const result = await doSomething();

    return NextResponse.json({ result }, { headers: corsHeaders });
  } catch (error) {
    console.error('Error in endpoint:', error);
    return NextResponse.json(
      { error: error instanceof Error ? error.message : 'Unknown error' },
      { status: 500, headers: corsHeaders }
    );
  }
}
```

3. **For X handle validation** (if applicable):
```typescript
const HANDLE_REGEX = /^[a-zA-Z0-9_]{1,15}$/;
if (!handle || !HANDLE_REGEX.test(handle)) {
  return NextResponse.json(
    { error: 'Invalid X handle format.' },
    { status: 400, headers: corsHeaders }
  );
}
```

4. **For database operations**, import from `@/db`:
```typescript
import { db, tableName } from '@/db';
import { eq, gt, and } from 'drizzle-orm';
```

## Existing Endpoints Reference

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/api/analyze-account` | POST | Analyze X account with Grok |
| `/api/generate-image` | POST | Generate images (rate-limited) |
| `/api/roast-account` | POST | Generate roast letter |
| `/api/fbi-profile` | POST | Generate FBI profile |

## Examples

- "Create an endpoint to fetch user stats" → Create `app/api/user-stats/route.ts`
- "Add a health check endpoint" → Create `app/api/health/route.ts` with GET handler

## Guardrails

- Always include CORS headers on all responses
- Always include OPTIONS handler for preflight requests
- Check environment variables exist before using
- Use try/catch with proper error responses
- Log errors with console.error for debugging
- Never expose API keys in responses

Related Skills

add-route-context

16
from diegosouzapw/awesome-omni-skill

为Flutter页面添加路由上下文记录功能,支持日期等参数的AI上下文识别。当需要让AI助手通过"询问当前上下文"功能获取页面状态(如日期、ID等参数)时使用。适用场景:(1) 日期驱动的页面(日记、活动、日历等),(2) ID驱动的页面(用户详情、订单详情等),(3) 任何需要AI理解当前页面参数的场景

python-development-python-scaffold

16
from diegosouzapw/awesome-omni-skill

You are a Python project architecture expert specializing in scaffolding production-ready Python applications. Generate complete project structures with modern tooling (uv, FastAPI, Django), type hint

fastapi-router-py

16
from diegosouzapw/awesome-omni-skill

Create FastAPI routers with CRUD operations, authentication dependencies, and proper response models. Use when building REST API endpoints, creating new routes, implementing CRUD operations, or add...

api-routes

16
from diegosouzapw/awesome-omni-skill

Generate secure TanStack Start API routes with authentication, rate limiting, validation, and proper error handling. Use when creating API endpoints, REST resources, or backend logic.

api-route

16
from diegosouzapw/awesome-omni-skill

Create a new Next.js API route with x402 micropayment middleware

api-route-creator

16
from diegosouzapw/awesome-omni-skill

Creates Next.js 16 API routes with auth, validation, and tenant scoping. Use when creating API endpoints.

api-route-conventions

16
from diegosouzapw/awesome-omni-skill

Expert knowledge on Next.js API route patterns, authentication with getAuthOrTest, error handling, response formats, rate limiting, and webhook verification. Use this skill when user asks about "create api endpoint", "api route", "error handling", "authentication", "next.js api", or "route handler".

api-integration-test-scaffolder

16
from diegosouzapw/awesome-omni-skill

Generates integration tests for frontend → backend → Genkit flow connections. Use when creating E2E API tests.

api-endpoint-scaffold

16
from diegosouzapw/awesome-omni-skill

Scaffold new Next.js API endpoints with authentication, rate limiting, and tests. Use when creating new API routes, adding endpoints, or building API features.

m365-agent-scaffolder

16
from diegosouzapw/awesome-omni-skill

Quickly scaffolds new Microsoft 365 Copilot declarative agent (M365 agent, copilot agent, agent, declarative copilot, copilot) projects using ATK CLI. Collects project information and creates the initial project structure. Use only when creating a new empty M365 Copilot agent project from scratch.

agentbox-openrouter

16
from diegosouzapw/awesome-omni-skill

Set up OpenRouter as your LLM provider. Guides through account creation, API key setup, config, and making it the default model. Use when a user wants to use OpenRouter models like Claude Sonnet 4.5.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development