TECHNOLOGY LAB · SYSTEMS ENGINEERING

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

hello

A minimal HTML response and an explicit route.

hello2

Inspect methods, raw queries, headers, and bounded bodies.

hello_json

JSON user lookup, with explicit ID parsing.

simple_router

Functions, stateful routes, and a synchronized counter.

routes

Static and dynamic responses in one router.

serve

Serve immutable embedded assets through explicit routes.

runtime_file

Download a runtime-opened file using fixed copy scratch on application workers.

decoded_forms

An allocator-backed iterator: decoded names and values, ordered duplicates, explicit lifetimes.

sendfile

File content as an embedded asset; no sendfile syscall.

senderror

Controlled errors, with no client-visible stack trace.

accept

Explicit, bounded content negotiation.

mustache

A greeting form and user cards: startup templates, typed data, bounded HTML.

continuations

Many waiting streams, a small worker pool: typed flush, wait, and finish callbacks.

streaming

Write, flush, sleep, and write again through a standard Zig writer.

jobs

A complete application: Mustache, cookie sessions and live job progress over bounded SSE.

app_basic

Typed Shared, endpoint state, and instance shutdown.

app_errors

Error mapping and discarded private response drafts.

endpoint

Bounded user CRUD on explicit application workers.

app_auth

Public authentication middleware and typed request locals.

endpoint_auth

Stateful endpoints with an explicit authentication check.

middleware

Public ordered before/after/cleanup hooks and typed request locals.

middleware_with_endpoint

Endpoint composition with an early-stop path.

userpass_session

32 reusable sessions, fixed server expiry, and logout across devices.

cookies

Borrowed cookie input, explicit expiry, and validated Set-Cookie output.

http_params

Raw duplicates and explicit query versus form decoding.

bindataformpost

One flat loop for fields and files, with bounded previews.

Build all examples, or run one
zig build examples -Doptimize=ReleaseSafe
zig build run-http_params -Doptimize=ReleaseSafe -- --port 8080

Cookies 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 →