Server functions
Guide: Server functions.
Declaring
pub const Actions = struct {
pub fn name(args: struct { … }) ReturnType { … }
};One struct argument; JSON-encodable return (or void, or an error union). Generated per function: /api/<fn> route (decode → dispatch → encode, CSRF-checked) and typed client stubs.
Generated client stubs (@import("app_client"))
| Stub | Behavior |
|---|---|
<fn>_call(args, on_reply) | correlated round-trip; reply handler gets the typed value |
<fn>_post(args) | fire-and-forget POST |
<fn>_invoke(arena, args) | direct dispatch (host/server side) |
Chunk-side primitives
| Export | Signature |
|---|---|
serverFnPost | (name, body_json) void |
serverFnPostRid | (name, body, rid) void — explicit request id |
registerResponseHandler | (route, fn ([*]const u8, u32) void) void |
registerResponseHandlerOnce | one-shot variant |
nextReqId | () u32 |
fetchSignal | (comptime T, action_name, args, signal_name) void — settle a signal from a server fn (i32 and []const u8 settlers) |
fetchToExport | (api_name, island, export_name) void — reply bytes to a chunk export |
Reply envelope: value-returning actions reply {"value": <encoded>}; handlers unwrap with doc.get("value"). Errors reply with an error envelope instead.
Server-side direct call
ctx.serverFn(api.Actions.getCount, .{}) — skips HTTP entirely during SSR.
Push channels
/push?channel=<name> SSE endpoint with ring history and Last-Event-ID resume. Chunk: pushSubscribe(channel, island,
export_name) bool (frames land in export fn name(ptr: u32, len:
u32)), pushUnsubscribe(channel, island). Server publishes via push.publish(channel, frame) (publisher threads opt in by @hasDecl hooks — see Tooling).