⚙️

REST API Endpoint Generator

Generate a complete CRUD API endpoint with validation and error handling

Beginner⚙️ Backendclaude
prompt template
Create a complete REST API for a [RESOURCE_NAME] resource.

**Fields:** [LIST_FIELDS_WITH_TYPES — e.g., "title: string, price: number, category: enum(electronics,books,clothing), isActive: boolean"]

Generate the following for Next.js API routes (App Router):
1. **GET /api/[resource]** — list all with pagination, sorting, and filtering
2. **GET /api/[resource]/[id]** — get single by ID
3. **POST /api/[resource]** — create with input validation
4. **PATCH /api/[resource]/[id]** — partial update
5. **DELETE /api/[resource]/[id]** — soft delete

For each endpoint include:
- TypeScript types for request/response
- Input validation with clear error messages
- Proper HTTP status codes (200, 201, 400, 404, 500)
- Try/catch with consistent error response shape
- SQL queries using parameterized statements (no ORM)

Also generate:
- The SQL CREATE TABLE statement
- A shared types file
- A shared db utility for running queries

How to Use This Prompt

  1. 1Copy the prompt template above
  2. 2Paste into claude
  3. 3Replace [bracketed placeholders] with your specific project details
  4. 4Iterate on the AI output to refine and customize the results