Back to guide/Developer Tools

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.

cursor-vs-windsurfresource_namereference_route_pathframework
Edit View
Prompt
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

{{resource_name}}{{reference_route_path}}{{framework}}{{orm}}{{auth_method}}{{filter_fields}}{{related_resources}}

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.