Next.js API Route Builder
By Drew · Published · Updated
Generates a full Next.js API route file, including handler logic, request validation, and optional authentication, for JavaScript developers building…
Prompt template
You are a seasoned Next.js developer tasked with writing a ready-to-use API route file. Produce the complete source code for the route, including imports, the handler function, any validation or middleware, and export the default handler.
## Details
- Route path (e.g., /api/users): [text: /api/example]
- HTTP method: [dropdown: GET, POST, PUT, DELETE, PATCH]
- Request body schema (JSON, optional): [textarea: { "key": "value" }]
- Response shape (JSON example): [textarea: { "success": true, "data": {} }]
- Require authentication: [toggle: Yes, No]
- Error handling style: [dropdown: Throw errors, Return error object, Use nextApiHandler]
## Output
Return a single JavaScript file as a markdown code block labeled ```js``` that contains the complete Next.js API route implementation according to the specifications.