smithery/applelamps

new-api-route

Scaffold new Next.js API routes with proper patterns. Use when user mentions "create endpoint", "new API route", "add route", or "API for".

Installation

$ npx skills add smithery/applelamps --skill new-api-route

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery/applelamps.

npx skills add smithery/applelamps

Browse all from smithery/applelamps

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,603 B
  • docs SUMMARY.md 160 B

History

  1. First recorded snapshot · 0 installs

SKILL.md

New API Route

Create API routes following project conventions for Next.js App Router.

Instructions

  1. Determine route path and HTTP methods needed
  1. Create route file at src/app/api/<path>/route.ts
  1. Use this template:

```typescript 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 tablename ORDER BY createdat 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 } ); } } ```

  1. For admin routes, place under src/app/api/admin/
  1. Add types to src/lib/db.ts if needed

Project Patterns

  • Always use force-dynamic for 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