Baz / Examples
Learn from working code
Twenty-six examples, from Zap ports to streaming and service composition, using Baz’s public API. Every card opens maintained source in the reader. Pick a small example, then follow its types.
Application recipes → LAN binding, runtime downloads, decoded field iteration, and custom errors.
Build real pages with Mustache templates: a greeting form, typed user cards, and reusable partials. Parse once at startup and render straight into reserved HTML storage. The complete Zig example is just 52 lines → See the rendered preview →
26 of 26 examples
A minimal HTML response and an explicit route.
hello2Inspect methods, raw queries, headers, and bounded bodies.
hello_jsonJSON user lookup, with explicit ID parsing.
simple_routerFunctions, stateful routes, and a synchronized counter.
routesStatic and dynamic responses in one router.
serveServe immutable embedded assets through explicit routes.
runtime_fileDownload a runtime-opened file using fixed copy scratch on application workers.
decoded_formsAn allocator-backed iterator: decoded names and values, ordered duplicates, explicit lifetimes.
sendfileFile content as an embedded asset; no sendfile syscall.
senderrorControlled errors, with no client-visible stack trace.
acceptExplicit, bounded content negotiation.
mustacheA greeting form and user cards: startup templates, typed data, bounded HTML.
continuationsMany waiting streams, a small worker pool: typed flush, wait, and finish callbacks.
streamingWrite, flush, sleep, and write again through a standard Zig writer.
jobsA complete application: Mustache, cookie sessions and live job progress over bounded SSE.
app_basicTyped Shared, endpoint state, and instance shutdown.
app_errorsError mapping and discarded private response drafts.
endpointBounded user CRUD on explicit application workers.
app_authPublic authentication middleware and typed request locals.
endpoint_authStateful endpoints with an explicit authentication check.
middlewarePublic ordered before/after/cleanup hooks and typed request locals.
middleware_with_endpointEndpoint composition with an early-stop path.
userpass_session32 reusable sessions, fixed server expiry, and logout across devices.
cookiesBorrowed cookie input, explicit expiry, and validated Set-Cookie output.
http_paramsRaw duplicates and explicit query versus form decoding.
bindataformpostOne flat loop for fields and files, with bounded previews.
zig build examples -Doptimize=ReleaseSafe
zig build run-http_params -Doptimize=ReleaseSafe -- --port 8080Cookies and redirects are public APIs, with explicit expiry and a local login/logout example. Middleware, authentication policy and session storage remain explicit application code. Read the complete catalog and its deliberate adaptations →