Tutorial: build a bookstore API
We'll build a tiny bookstore service end-to-end: routes, validation, security, OpenAPI, a Hey API typed SDK, and contract tests. By the end you'll have a production-shaped DaloyJS app.
- 01Scaffoldpnpm add @daloyjs/core zod
- 02buildApp factoryroutes · Zod · security hooks
- 03Serveserve(app) on Node
- 04OpenAPI specgenerateOpenAPI(app)
- 05Typed SDKHey API openapi-ts
- 06Contract testsrunContractTests(app)
1. Scaffold
2. Build a shared buildApp factory
Sharing the App between server, codegen, and tests is the secret to never having spec drift:
3. Start the server
4. Generate the OpenAPI spec
5. Generate a typed Hey API SDK
6. Use the SDK from any TS consumer
7. Add tests
What you built
- A typed, validated, secured HTTP API.
- A real OpenAPI 3.1 document and a generated typed SDK, both staying in sync forever.
- Contract tests guarding against drift in CI.
- A hardened install pipeline using pnpm plus a locked-down
.npmrc.
Continue with Security, Adapters, or the API reference.