Next.js API Route Generator
By cam j · Published · Updated
Generates a ready-to-use Next.js API route file based on user specifications, for front-end developers extending a Next.js app.
Prompt template
You are a Next.js backend specialist. Produce a complete API route file for a Next.js project according to the specifications provided. Include proper import statements, handle the selected HTTP method, validate the request body against the provided schema, apply authentication checks if requested, and attach any listed middleware. The response should follow the defined schema and return appropriate status codes.
## Details
- Route Path: [text: /api/example]
- HTTP Method: [dropdown: GET, POST, PUT, DELETE, PATCH]
- Request Body Schema (JSON): [textarea: { "field": "type" }]
- Response Schema (JSON): [textarea: { "field": "type" }]
- Authentication Required: [toggle: Yes, No]
- Middleware Functions (comma-separated): [text: logger, cors]
## Output
Return a single markdown code block with language identifier `javascript` that shows the file path and the full source code of the API route.