Lovable prompt to build a REST API
Lovable's backend is Supabase, not a bare Express server, so this prompt specifies the API as edge functions with Postgres behind them. You end up with five CRUD endpoints covering create, list, read, update, and soft delete, plus auth checks, consistent JSON errors, and a small test page for verifying status codes in the browser.
Last updated
Build a REST API for managing {{resource}}, implemented as Supabase Edge Functions with a minimal admin page for exercising it.
Endpoints:
- POST /{{resource}}: create a record, validate required fields, return 201 with the created row.
- GET /{{resource}}: list with pagination (limit and offset params, default 20, max 100) and a sort param.
- GET /{{resource}}/:id: return the record or a 404 JSON body.
- PATCH /{{resource}}/:id: partial update, reject unknown fields with 400.
- DELETE /{{resource}}/:id: soft delete via a deleted_at column; exclude soft-deleted rows from every read.
Data model: a {{resource}} table in Postgres with id (uuid), created_at, updated_at, deleted_at, plus whatever fields fit {{resource}}. Propose the columns and wait for my confirmation before running the migration.
Behavior:
- Require a Supabase auth JWT on every endpoint; respond 401 without one.
- Scope rows to the authenticated user with Row Level Security policies, not only WHERE clauses.
- Errors are JSON: { "error": { "code", "message" } } with correct status codes (400 validation, 401 auth, 404 missing, 500 unexpected).
- Handle malformed JSON bodies and invalid uuids without the function crashing.
These endpoints must be callable with curl from outside the app; do not implement them as supabase-js calls inside React components.
Admin page: list records, a create form, and a panel showing the raw status code and JSON of the last request.
When done, print each endpoint with an example curl command against the deployed function URLs so I can verify all five paths.Customize it
Runs in your browser. Nothing you type here is sent anywhere.
Build a REST API for managing users, implemented as Supabase Edge Functions with a minimal admin page for exercising it.
Endpoints:
- POST /users: create a record, validate required fields, return 201 with the created row.
- GET /users: list with pagination (limit and offset params, default 20, max 100) and a sort param.
- GET /users/:id: return the record or a 404 JSON body.
- PATCH /users/:id: partial update, reject unknown fields with 400.
- DELETE /users/:id: soft delete via a deleted_at column; exclude soft-deleted rows from every read.
Data model: a users table in Postgres with id (uuid), created_at, updated_at, deleted_at, plus whatever fields fit users. Propose the columns and wait for my confirmation before running the migration.
Behavior:
- Require a Supabase auth JWT on every endpoint; respond 401 without one.
- Scope rows to the authenticated user with Row Level Security policies, not only WHERE clauses.
- Errors are JSON: { "error": { "code", "message" } } with correct status codes (400 validation, 401 auth, 404 missing, 500 unexpected).
- Handle malformed JSON bodies and invalid uuids without the function crashing.
These endpoints must be callable with curl from outside the app; do not implement them as supabase-js calls inside React components.
Admin page: list records, a create form, and a panel showing the raw status code and JSON of the last request.
When done, print each endpoint with an example curl command against the deployed function URLs so I can verify all five paths.Same task in other tools
Questions about this prompt
Why does the prompt build the API as Supabase Edge Functions?
Lovable does not scaffold standalone Express or Fastify servers; its server-side story is Supabase. Edge functions are the piece of that stack you can hit with curl from outside the app, which is what makes this a real API rather than internal data access.
How do I change the fields on the resource?
The prompt tells Lovable to propose columns and wait for confirmation, so answer that message with your exact field list and types. If you already know the schema, replace the data model paragraph with it and delete the confirmation step.
What if the endpoints only work from inside the generated app?
That usually means Lovable implemented the logic as supabase-js calls in React components instead of functions. Quote the line requiring curl access, and ask it to move the logic into edge functions and return the deployed URLs.