Documentation
Quickstart
This guide walks you from zero to a deployed Kynetra FX API. It covers creating an app, registering routes and middleware, running the app locally, and deploying to Cloudflare Workers. Total time: under five minutes.
Prerequisites#
- Node.js 18+ (or Bun / Deno) installed.
- A Cloudflare account (free) if you want to deploy — skip the deploy step otherwise.
Walkthrough#
Create a new project
Use the Kynetra FX CLI to scaffold a project. Choose the cloudflare runtime for this guide — substitute node, bun, or deno as needed.
npx @kynetra/fx-cli new my-api --runtime cloudflarecd my-apinpm installAlternatively, install manually into an existing project:
npm install @kynetra/fx @kynetra/fx-cloudflareCreate your app
Create src/app.ts and define a createFX() instance. This is the entry point for all routes and middleware.
import { createFX } from '@kynetra/fx' export const app = createFX({ name: 'my-api' })Add middleware
Register app-level middleware before your routes. Built-ins like requestId() and logger() run on every request.
import { createFX, requestId, logger, cors } from '@kynetra/fx' export const app = createFX({ name: 'my-api' }) app.use(requestId())app.use(logger())app.use(cors())Register routes
Add route handlers with app.get, app.post, etc. Each handler receives a ctx and returns a Response.
import { createFX, requestId, logger, cors } from '@kynetra/fx' export const app = createFX({ name: 'my-api' }) app.use(requestId())app.use(logger())app.use(cors()) // Static routeapp.get('/', (ctx) => ctx.json({ status: 'ok' })) // Dynamic param routeapp.get('/users/:id', (ctx) => { const { id } = ctx.params return ctx.json({ id, name: 'Alice' })}) // POST with body parsingapp.post('/users', async (ctx) => { const body = await ctx.jsonBody() // body is Record<string, unknown> return ctx.json({ created: true, body }, { status: 201 })})Export for your runtime
For Cloudflare Workers, wrap the app with cloudflare(). For Bun or Deno, pass app.fetch directly.
// Cloudflare Workersimport { cloudflare } from '@kynetra/fx-cloudflare'import { app } from './app' return cloudflare(app)// Bunimport { app } from './app' Bun.serve({ fetch: app.fetch, port: 3000 })// Node.js (requires @kynetra/fx-node)import { serve } from '@kynetra/fx-node'import { app } from './app' serve(app, { port: 3000 })Run locally
For Cloudflare Workers, use Wrangler:
npx wrangler dev src/index.tsFor Node.js or Bun, run directly:
# Nodenpx ts-node src/index.ts # Bunbun run src/index.tsTest it:
curl http://localhost:8787/# {"status":"ok"} curl http://localhost:8787/users/42# {"id":"42","name":"Alice"}Deploy
For Cloudflare Workers, deploy with Wrangler:
npx wrangler deployWrangler prints the deployment URL. Your API is live on the Cloudflare network globally.
Tip
wrangler.toml example and D1 database integration, see Cloudflare adapter.Complete minimal app#
Here is the entire minimal application in a single file:
import { createFX, requestId, logger, cors } from '@kynetra/fx'import { cloudflare } from '@kynetra/fx-cloudflare' const app = createFX({ name: 'my-api' }) app.use(requestId())app.use(logger())app.use(cors()) app.get('/', (ctx) => ctx.json({ status: 'ok' })) app.get('/users/:id', (ctx) => ctx.json({ id: ctx.params.id })) app.post('/users', async (ctx) => { const body = await ctx.jsonBody() return ctx.json({ created: true, body }, { status: 201 })}) return cloudflare(app)Next steps#
- Routing — static, dynamic, and wildcard routes; match precedence.
- Middleware — onion model, ordering, and all built-ins.
- Context — the full
ctxAPI reference. - Responses —
json,text,html,stream, and rawResponse. - Contracts — validated inputs, OpenAPI, and the typed client.
- Project Structure — recommended layout for larger apps.