Server

~import orisha/index

Orisha — the contract.

lib/index.k · 29 tors

Orisha — the contract. · 40 more lines
Orisha — the contract. Everything Orisha declares lives here, and nothing in this file is Zig, so there is no parser to switch out of and not a single `~` anywhere. The Zig that implements it — the socket calls, the request parser, the router transform — sits in the companion `index.kz` beside this file. Same stem, same module: the compiler merges them. That split is the whole reason this file reads the way it does. These declarations used to live inside 1,056 lines of Zig, which forced a `~` onto every one of them; the character was never about the Koru, it was about the host language it was sharing a file with. Public API: orisha:serve(port) - Start server (calls abstract handler for each request) orisha:handler - Abstract event users implement for request handling orisha:router(req) - Pattern-branch router transform orisha:static(name, root, ...) - Declare static files to embed at compile time orisha:static-router(name) - Transform: inline static file lookup + fallback orisha:header(req, name) - One request header, scanned lazily -> ?string orisha:cookie(req, name) - One pair out of the Cookie header -> ?string orisha:form(req, name) - One urlencoded field out of req.body -> ?string orisha:query-param(req, name) - The same codec over req.query -> ?string Response.extra_headers - CRLF block of response headers (Location, Set-Cookie, ...) spliced into the head Example (simplest server): ~orisha:handler -> { status: 200, body: "Hello!", content_type: "text/plain" } ~orisha:serve(port: 3001) Example (API + static): ~orisha:handler = orisha:router(req) ! [GET /api/health] -> { status: 200, body: "ok", content_type: "application/json" } ! [*] |> orisha:static-router(name: "site") Example (pure static site): ~import orisha ~orisha:static(name: "site", root: "build", fallback: "200.html") ~orisha:handler = orisha:static-router(name: "site") ~orisha:serve(port: 3000)

Phantom lifecycles

Derived from the phantom labels in the declarations below — state! issues an obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.

string carries the label <*@scoped> with no obligation attached — a dimension, not a lifecycle.

handler

abstractretain lib/index.k:82

handler-lite

abstractretain lib/index.k:98

init

abstract lib/index.k:118

release-body

lib/index.k:168

respond

<*@scoped> lib/index.k:176

render-target

lib/index.k:188

respond-filled

lib/index.k:189

serve-file

lib/index.k:199

grpc-sum-reply

lib/index.k:211

query-param

lib/index.k:243

ws-accept

lib/index.k:285

generation-bump

lib/index.k:296

router

comptimetransform lib/index.k:361

static

comptimenorun lib/index.k:390

static-router

comptimetransform lib/index.k:404