GitHub Copilot prompt to build a REST API
This prompt turns a bare {{resource}} model into a layered CRUD API: routes, service, repository, validation, and integration tests that match the conventions already in your repo. GitHub Copilot handles it well in Chat with agent mode, which runs the suite itself, or in Copilot Edits if you want a reviewable diff per file.
Last updated
Working with Copilot Edits file by file inside VS Code: begin by opening src and mirroring its existing layout. Step 1: a route module in {{language}} declaring five operations for {{resource}}: collection GET paged by a cursor token plus a limit count, single-record GET, POST, PATCH, DELETE. Step 2: a service module holding business rules, and a repository that talks to {{database}} only through bound parameters or the ORM this project already ships; concatenated SQL strings are forbidden. Step 3: register the router inside the application entry file. Behavior contract: schema-check incoming JSON and reply 400 naming which fields failed, 404 when an id matches nothing, 409 for uniqueness conflicts. Step 4: integration tests for one successful round trip, one schema-violating payload, one lookup of an absent record. Run the project's test command and report each added or modified file.Customize it
Runs in your browser. Nothing you type here is sent anywhere.
Working with Copilot Edits file by file inside VS Code: begin by opening src and mirroring its existing layout. Step 1: a route module in TypeScript declaring five operations for users: collection GET paged by a cursor token plus a limit count, single-record GET, POST, PATCH, DELETE. Step 2: a service module holding business rules, and a repository that talks to PostgreSQL only through bound parameters or the ORM this project already ships; concatenated SQL strings are forbidden. Step 3: register the router inside the application entry file. Behavior contract: schema-check incoming JSON and reply 400 naming which fields failed, 404 when an id matches nothing, 409 for uniqueness conflicts. Step 4: integration tests for one successful round trip, one schema-violating payload, one lookup of an absent record. Run the project's test command and report each added or modified file.
Same task in other tools
Questions about this prompt
Should I run this in Copilot Chat or Copilot Edits?
Use agent mode in Chat if you want it to run the test suite itself and fix failures. Use Edits when you would rather review a diff per file before anything lands. The prompt works in both; only the verification step needs the agent.
Copilot generated Express but my project uses Fastify. How do I stop that?
Copilot leans toward the framework it has seen most often for {{language}} unless the repo tells it otherwise. Open your app entry point before prompting or add #file:src/app.ts so it sees the real framework, and name Fastify explicitly in the first sentence.
Can I switch the pagination from cursor to offset?
Swap the limit and cursor params for page and pageSize if your API uses offset paging, and say which response field carries the total count. Copilot will thread that choice through the repository query and the tests.