Create and build an API
Use the CLI to create a project, add a GET endpoint, check its response, and run the production build.
Create an application, add GET /ping, and call the same endpoint in development and from a production build. You will use the CLI installed in the application.
1. Create the application
From the directory where you keep projects, run:
bunx create-relkit@latest relkit-cli-demo
cd relkit-cli-demo
cp .env.example .envThe generator installs the minimal starter and its local CLI. If prompted, confirm the new destination. Keep this terminal in relkit-cli-demo for the remaining commands. For an existing minimal application, use its root directory and keep its current .env.
Creation options explains deferred installation, Git initialization, and supported starter choices.
2. Add an endpoint
Inspect the command, then create a new route:
bun run relkit add route --help
bun run relkit add route /ping --mode routeThe second command creates src/routes/ping/route.ts with a GET handler that returns { "ok": true }. The directory determines the URL. --mode route selects a standalone HTTP handler, which is useful for this small response. For business operations with input and output schemas, use a service-backed route.
If /ping already exists, choose a new path and use that path in the requests below. Scaffolding rejects collisions instead of overwriting existing files.
3. Check the application
Run these checks from the same directory:
bun run check
bun run typecheck
bun run testAll three commands should finish successfully. check validates the application’s structure, typecheck checks TypeScript, and test runs the starter tests. Adding a route does not generate tests for that route; you will verify its response next. See Testing when adding behavior of your own.
4. Run and call the endpoint
Start development:
bun run devKeep it running. When the server is ready, send a request from the second terminal:
curl -i http://localhost:3000/pingExpect HTTP 200 and this JSON body:
{ "ok": true }If connection fails, wait for readiness and check Terminal 1 for diagnostics. If the response is 404, check the route directory and whether validation succeeded. Troubleshooting explains how to follow diagnostics back to the file to repair.
5. Build and run production output
In Terminal 1, press Ctrl+C to stop development. Build and start from the same application directory:
bun run build
bun run startThe build writes .relkit/build; start runs that output. When it is ready, repeat the request in Terminal 2:
curl -i http://localhost:3000/pingExpect HTTP 200 and { "ok": true } again. Production does not watch source changes: rebuild after editing. Press Ctrl+C in Terminal 1 when finished. Building and starting locally do not deploy the application.
Related tasks
Add business behavior with Your first service.
Choose another capability in Add application files.
Follow the full Orders tutorial for persistence, authentication, and tests.
Look up flags in the command reference, including
dev, check,
build, and start.