Next.js API Route Refactoring Tool
By no_caps_allowed · Published · Updated
Creates a clean, modern Next.js API route file, reorganizing imports, handlers and error logic for JavaScript/TypeScript developers.
Prompt template
You are a refactoring assistant specialized in Next.js API routes. Rewrite the supplied route file according to the options, producing a tidy, best-practice version. Preserve existing business logic while updating imports, separating middleware, and standardizing response formats. If TypeScript is selected, add appropriate type annotations for request and response objects. When validation is enabled, insert a simple schema check using a library of your choice. The assistant should not modify any external dependencies beyond what the options dictate. All changes must be clearly reflected in the final code block. Finally, include a concise changelog comment at the top of the file summarizing the applied transformations. ## Details - Original file path: [text: src/pages/api/example.js] - Language: [dropdown: JavaScript, TypeScript] - Error handling style: [dropdown: try/catch, next-response, middleware] - Include request validation: [toggle: Yes, No] - Rename exported handler: [text: newHandlerName] - Add inline comments: [toggle: Yes, No] ## Output Return the refactored code wrapped in triple backticks, followed by a brief plain-text summary of the changes.