API Route Generator
Both editors excel at pattern-matching from reference code. Pointing to an existing route as a style guide produces remarkably consistent output. The comprehensive endpoint list prevents incomplete CRUD implementations.
Generate a REST API route for {{resource_name}} following this project's existing patterns. Reference route: {{reference_route_path}} (use this as the style guide) Framework: {{framework}} ORM: {{orm}} Auth: {{auth_method}} Endpoints to create: - GET /api/{{resource_name}} — list with pagination, filtering by {{filter_fields}}, sorting - GET /api/{{resource_name}}/[id] — single resource with {{related_resources}} included - POST /api/{{resource_name}} — create with Zod validation - PATCH /api/{{resource_name}}/[id] — partial update - DELETE /api/{{resource_name}}/[id] — soft delete if project uses it, hard delete otherwise Each endpoint must include: - Auth check (match the pattern in {{reference_route_path}}) - Input validation with descriptive error messages - Proper HTTP status codes (201 for create, 204 for delete, 422 for validation errors) - Rate limiting if the project has it - Consistent response shape matching existing endpoints Also generate: - TypeScript types for request/response bodies - A Zod schema for the create and update payloads - An API client function that the frontend can use to call each endpoint
Variables to customize
Why this prompt works
Both editors excel at pattern-matching from reference code. Pointing to an existing route as a style guide produces remarkably consistent output. The comprehensive endpoint list prevents incomplete CRUD implementations.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
Get thorough code reviews with actionable feedback tailored to your language, framework, and standards.
Context-Aware Code CompletionProviding the surrounding code and project context lets the model match existing patterns exactly. The constraint against modifying existing code prevents unwanted side effects.
Inline Code SuggestionConstraining suggestions to match existing style and scope produces insertions that feel native to the codebase. The 'no explanation' rule mimics real inline completion behavior.
Code ExplanationThe audience level parameter adjusts complexity automatically. Requiring a usage example ensures the explanation is practical, not just theoretical.