Next.js API Route Builder skill for Claude and Codex
Writes a complete JavaScript Next.js API route you can drop into pages/api: method guard, optional body validation, an optional auth check, and the…
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when a plain JavaScript API route for pages/api is needed fast with a method guard, optional auth, and a chosen error-handling style. Do not use for strict TypeScript routes with zod and next-auth, or refactoring a route that already exists. Related topics: coding, next.js.
What it will ask you for
- Route path (free text, e.g. "/api/example")
- HTTP method (choose one: GET, POST, PUT, DELETE, PATCH)
- Request body schema (optional) (longer free text)
- Response shape (longer free text)
- Require authentication (choose one: Yes, No)
- Error handling style (choose one: Throw errors, Return error object, Use nextApiHandler)
How it works
- Open with the method guard so other methods receive 405 and an Allow header.
- Insert the auth check at the top when required, returning 401 before the body is read, with a marked plug-in point for the real check.
- Validate required fields and types by hand against the given schema and answer 400 with the field list.
- Implement the handler in the chosen error-handling style and shape the success response exactly like the example.
- Comment each block in one line and return the file as a js code block headed by its path comment.
What you get
A single code block tagged js: a path comment, imports if any, the auth helper, the handler with method guard, validation, business logic placeholder, and the default export.
What it watches out for
- Pulling in a validation library for a route whose whole appeal is no new dependencies.
- Mixing thrown errors and returned error objects in one handler, so callers cannot predict the failure shape.
- Reading req.body on a GET route, which is always undefined and masks a wrong method.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.