Next.js API Route Generator skill for Claude and Codex
Generates a JavaScript Next.js API route that runs your existing middleware functions by name before the handler, validates the body against your schema, and…
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 JavaScript route must run named existing middleware functions in order before the handler and still validate the body and return a set shape. Do not use for TypeScript routes, standalone validation middleware, or debugging 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 (JSON) (longer free text)
- Response schema (JSON) (longer free text)
- Authentication required (choose one: Yes, No)
- Middleware functions (comma separated) (free text, e.g. "logger and cors")
How it works
- Derive the file path from the route path and put it in the first comment line.
- Import each named middleware and run them in the given order through a promise-based runMiddleware helper that stops the chain on failure.
- Add the 405 method guard and the 401 auth check after the chain when authentication is required.
- Validate presence and type of every body field against the schema and respond 400 with the offending fields.
- Build the response from the response schema with the status code matched to the method and output one javascript code block.
What you get
One markdown code block tagged javascript: a file path comment, imports, the runMiddleware helper, the handler with chain, guards, validation, and response, and the default export.
What it watches out for
- Calling callback-style middleware without awaiting a promise wrapper, so the handler responds before the middleware finishes.
- Continuing the chain after a middleware already sent a response, which raises headers already sent.
- Mapping a dynamic route like /api/users/:id to a flat file instead of the bracketed segment filename.
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.