Kynetra FX

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#

1

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.

terminal
npx @kynetra/fx-cli new my-api --runtime cloudflare
cd my-api
npm install

Alternatively, install manually into an existing project:

terminal
npm install @kynetra/fx @kynetra/fx-cloudflare
2

Create your app

Create src/app.ts and define a createFX() instance. This is the entry point for all routes and middleware.

src/app.ts
import { createFX } from '@kynetra/fx'
 
export const app = createFX({ name: 'my-api' })
3

Add middleware

Register app-level middleware before your routes. Built-ins like requestId() and logger() run on every request.

src/app.ts
import { createFX, requestId, logger, cors } from '@kynetra/fx'
 
export const app = createFX({ name: 'my-api' })
 
app.use(requestId())
app.use(logger())
app.use(cors())
4

Register routes

Add route handlers with app.get, app.post, etc. Each handler receives a ctx and returns a Response.

src/app.ts
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 route
app.get('/', (ctx) => ctx.json({ status: 'ok' }))
 
// Dynamic param route
app.get('/users/:id', (ctx) => {
const { id } = ctx.params
return ctx.json({ id, name: 'Alice' })
})
 
// POST with body parsing
app.post('/users', async (ctx) => {
const body = await ctx.jsonBody()
// body is Record<string, unknown>
return ctx.json({ created: true, body }, { status: 201 })
})
5

Export for your runtime

For Cloudflare Workers, wrap the app with cloudflare(). For Bun or Deno, pass app.fetch directly.

src/index.ts
// Cloudflare Workers
import { cloudflare } from '@kynetra/fx-cloudflare'
import { app } from './app'
 
return cloudflare(app)
src/index.ts (Bun)
// Bun
import { app } from './app'
 
Bun.serve({ fetch: app.fetch, port: 3000 })
src/index.ts (Node)
// Node.js (requires @kynetra/fx-node)
import { serve } from '@kynetra/fx-node'
import { app } from './app'
 
serve(app, { port: 3000 })
6

Run locally

For Cloudflare Workers, use Wrangler:

terminal
npx wrangler dev src/index.ts

For Node.js or Bun, run directly:

terminal
# Node
npx ts-node src/index.ts
 
# Bun
bun run src/index.ts

Test it:

terminal
curl http://localhost:8787/
# {"status":"ok"}
 
curl http://localhost:8787/users/42
# {"id":"42","name":"Alice"}
7

Deploy

For Cloudflare Workers, deploy with Wrangler:

terminal
npx wrangler deploy

Wrangler prints the deployment URL. Your API is live on the Cloudflare network globally.

Tip

For a full wrangler.toml example and D1 database integration, see Cloudflare adapter.

Complete minimal app#

Here is the entire minimal application in a single file:

src/index.ts
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 ctx API reference.
  • Responsesjson, text, html, stream, and raw Response.
  • Contracts — validated inputs, OpenAPI, and the typed client.
  • Project Structure — recommended layout for larger apps.