BoilerPrompt
Bolt

Bolt prompt to build a REST API

This spec makes Bolt scaffold a complete Node and TypeScript REST API inside its browser-based WebContainer: CRUD routes, request validation, a consistent JSON error envelope, and seed data on startup. An HTML test page at the root route lets you fire every endpoint from the preview pane and read raw responses without leaving the tab.

Last updated

Prompt
Build a REST API in Node with TypeScript, using Express, for managing {{resource}} records, backed by {{database}}.

The in-browser container runs Node only, never a database server. If {{database}} is Postgres, MySQL, MongoDB, or Redis, read a connection string from an env var and point the data layer at a hosted instance. Without one, fall back to a JSON file store behind the same interface so the preview still works.

Endpoints:
- GET /api/{{resource}} with pagination (page and limit query params, default limit 20) and a total count in the response body
- GET /api/{{resource}}/:id, returning 404 with a JSON error body when the id does not exist
- POST /api/{{resource}} with request body validation; reject unknown fields and return 422 with per-field messages
- PATCH /api/{{resource}}/:id for partial updates, validating only the fields present
- DELETE /api/{{resource}}/:id, returning 204 on success and 404 for a missing id
- GET /api/health returning uptime, which store is active, and, when hosted, whether the database connection is alive

Data model: each record has an id, name, description, status (active or archived), createdAt, and updatedAt, plus two or three extra fields that fit a {{resource}}.

Behaviors:
- One JSON error envelope for every non-2xx response: { error: { code, message, details } }
- Request logging middleware printing method, path, status, and duration to the terminal
- CORS enabled so the preview page can call the API
- Seed 15 realistic records on startup so list responses are never empty

Also serve a plain HTML page at the root route documenting every endpoint with an example request, plus a form to POST a new record and buttons that hit each endpoint and print the raw JSON.

Structure the code as a server entry, routes, validation, and data access modules. After scaffolding, start the server and confirm /api/health and the list endpoint both return 200.

Customize it

Runs in your browser. Nothing you type here is sent anywhere.

Your customized prompt
Build a REST API in Node with TypeScript, using Express, for managing users records, backed by PostgreSQL.

The in-browser container runs Node only, never a database server. If PostgreSQL is Postgres, MySQL, MongoDB, or Redis, read a connection string from an env var and point the data layer at a hosted instance. Without one, fall back to a JSON file store behind the same interface so the preview still works.

Endpoints:
- GET /api/users with pagination (page and limit query params, default limit 20) and a total count in the response body
- GET /api/users/:id, returning 404 with a JSON error body when the id does not exist
- POST /api/users with request body validation; reject unknown fields and return 422 with per-field messages
- PATCH /api/users/:id for partial updates, validating only the fields present
- DELETE /api/users/:id, returning 204 on success and 404 for a missing id
- GET /api/health returning uptime, which store is active, and, when hosted, whether the database connection is alive

Data model: each record has an id, name, description, status (active or archived), createdAt, and updatedAt, plus two or three extra fields that fit a users.

Behaviors:
- One JSON error envelope for every non-2xx response: { error: { code, message, details } }
- Request logging middleware printing method, path, status, and duration to the terminal
- CORS enabled so the preview page can call the API
- Seed 15 realistic records on startup so list responses are never empty

Also serve a plain HTML page at the root route documenting every endpoint with an example request, plus a form to POST a new record and buttons that hit each endpoint and print the raw JSON.

Structure the code as a server entry, routes, validation, and data access modules. After scaffolding, start the server and confirm /api/health and the list endpoint both return 200.

Same task in other tools

Questions about this prompt

Why is the stack pinned to Node and TypeScript instead of letting me pick a language?

Bolt runs everything in a WebContainer, a Node runtime living in the browser tab, so a JavaScript or TypeScript server is the only kind that can actually start there. That matters because the last line of the prompt tells Bolt to boot the server and check two endpoints; ask for Python or Go and that step becomes impossible in the tab.

Why ask for an HTML test page instead of using curl in the terminal?

Bolt does have a terminal, but the preview pane gives a faster loop: one click per endpoint, response JSON on screen, and the page doubles as living documentation of the API surface. Delete it before deploying if you do not want it public.

My data disappears when the container restarts. Is that a bug?

No. The JSON file fallback lives inside the WebContainer, which resets between sessions. Set the {{database}} connection string to a hosted instance, or attach a Supabase project via Bolt's integrations panel, and the data access module starts writing somewhere that survives a reload.

Related prompts