BoilerPrompt
Claude Code

Claude Code prompt to build a REST API

This prompt has Claude Code scaffold a complete CRUD API from your terminal: routes, request validation, a database migration, and integration tests, delivered as reviewable file changes. Because the agent runs your migration and test suite itself, you end up with endpoints that already survived a red-green loop instead of untested generated source.

Last updated

Prompt
You are a terminal agent, so investigate before coding: list the repo tree and read any router or error-handling modules already present. Then build CRUD for {{resource}} in {{language}} on top of {{database}}. Routes: POST returning 201, GET by id returning 404 when absent, PATCH, DELETE returning 204, and a collection route driven by cursor and limit parameters for keyset paging. Reject malformed bodies with a 400 that itemizes each failing field; answer 409 when a unique column would collide. Also deliver a table migration, a pooled connection module, and GET /healthz that round-trips {{database}}. Place new code under src/ using conventions the project already follows, or establish sensible ones. Apply the migration, write integration coverage for a full create-read-update-delete cycle, a rejected payload, a missing id, and a cursor fetch of page two, then run everything from the shell and keep iterating until green. Close with a summary of files touched.

Customize it

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

Your customized prompt
You are a terminal agent, so investigate before coding: list the repo tree and read any router or error-handling modules already present. Then build CRUD for users in TypeScript on top of PostgreSQL. Routes: POST returning 201, GET by id returning 404 when absent, PATCH, DELETE returning 204, and a collection route driven by cursor and limit parameters for keyset paging. Reject malformed bodies with a 400 that itemizes each failing field; answer 409 when a unique column would collide. Also deliver a table migration, a pooled connection module, and GET /healthz that round-trips PostgreSQL. Place new code under src/ using conventions the project already follows, or establish sensible ones. Apply the migration, write integration coverage for a full create-read-update-delete cycle, a rejected payload, a missing id, and a cursor fetch of page two, then run everything from the shell and keep iterating until green. Close with a summary of files touched.

Same task in other tools

Questions about this prompt

Will Claude Code actually run the migration it writes?

Yes, if it can reach a database. It executes shell commands, so export the connection string before you start, or tell it to spin up a throwaway container for the run. If nothing is reachable it will still write the migration file and tell you it skipped execution.

How do I use this against an existing API instead of a fresh one?

Replace the scaffolding language with a pointer to your current router file and say new endpoints must follow its patterns. Also restrict scope, for example "only add the new resource routes, do not restructure existing ones".

My integration tests pass locally but hammer a shared database. What should I change?

Add one line telling the agent to run tests inside a transaction that rolls back, or against an isolated test database named in an env var. Claude Code will rework the test setup and rerun the suite to confirm.

Related prompts