Skip to content

Examples

All examples live in examples/ and are runnable.

ExampleRuntimeWhat it shows
examples/node-demo.tsNodeMinimal HTTP server with contracts
examples/bun-demo.tsBunBun.serve with validation
examples/todo-api.tsNodeFull CRUD: auth middleware, DI, OpenAPI, MCP
examples/mcp-demo.tsNodeMCP server over stdio
examples/ws-demo.tsBunWebSocket channels with presence
examples/workers-quickstart/WorkersCopy-paste wrangler project: DO + channels + presence
examples/workers-quickstart.mdWorkersSame project, explained file-by-file

Minimal Node demo

ts
import { t, contract, impl, createApp, listen } from '@carlos-tzin/tzin'

const health = contract({
  method: 'GET',
  path: '/health',
  responses: { 200: t.Object({ status: t.String() }) },
})

const healthRoute = impl(health, async () => ({
  status: 200 as const,
  body: { status: 'ok' },
}))

const app = createApp([healthRoute])
listen(app, 3000)

Released under the MIT License.