# Examples


Thirteen runnable programs cover the production patterns MuxMaster is built for. **Start with [REST API](/examples/rest-api)** for the canonical CRUD service, then jump straight to **[Maximum performance](/examples/max-performance)** to see every v1.1.0 opt-in working together (`PoolRequestBundle`, `PoolFastParams`, `HandleFast`, `UseFast`, plus an in-process `/bench` endpoint that reports the speed-up on your hardware).

The four v1.1.0 patterns under it — **versioning**, **server-sent events**, **upload file**, **reverse proxy** — each demonstrate a different way to satisfy the [pool lifetime contract](/docs/max-performance#lifetime-contract--what-you-must-not-do): synchronous handlers, long-lived streams, the drain-before-spawn rule for background work, and synchronous proxying. The remaining seven cover authentication, caching, operational concerns, and content rendering.

Every example mirrors its upstream `main.go` at the v1.1.0 tag verbatim — the code is the source of truth.


- [REST API example](/examples/rest-api) — A complete REST API built with MuxMaster: route grouping, JSON responses, parameter parsing, and a small in-memory store. CRUD over a single resource.
- [Maximum-performance example](/examples/max-performance) — Every v1.1.0 opt-in combined: PoolRequestBundle, PoolFastParams, HandleFast, UseFast, Mounted pprof, plus an in-process /bench endpoint that reports the live 2.4x speed-up.
- [Versioning example](/examples/versioning) — Path-based (/v1, /v2) and header-based (Accept: ...;v=N) API versioning on the same router, with nested admin groups and PoolRequestBundle for zero-alloc dispatch.
- [Server-sent events example](/examples/server-sent-events) — Pool-safe SSE streaming on MuxMaster: topic-hub fan-out, drop-on-slow-subscriber backpressure, periodic server tick, and an in-browser demo page.
- [Upload-file example](/examples/upload-file) — Multipart upload with PoolRequestBundle: single + multi + async handlers, the body-drain-before-spawn pattern, 32 MiB caps, path-traversal guard, streaming SHA-256.
- [Reverse-proxy example](/examples/reverse-proxy) — HTTP gateway with httputil.ReverseProxy on MuxMaster: catch-all routing, lock-free round-robin load balancing, per-route gating, and pool-safe synchronous dispatch.
- [Authentication example](/examples/authn) — HTTP Basic Authentication via the BasicAuth middleware, paired with ThrottlePerIP to defend against credential-stuffing attacks.
- [JWT example](/examples/jwt) — Bearer-token authentication via the JWTAuth middleware. Configures RequireExpiry: true (RFC 8725 §4.4) and shows the canonical OIDC integration shape.
- [OAuth2 example](/examples/oauth2) — OAuth 2.0 token introspection (RFC 7662) via the OAuth2Introspect middleware. Tokens are validated against an authorisation server, not locally.
- [Cache example](/examples/cache) — An in-memory TTL cache that avoids re-computing identical responses within a configurable horizon. For expensive, idempotent handlers.
- [Graceful shutdown example](/examples/graceful-shutdown) — Production graceful shutdown: signal handling, srv.Shutdown with a bounded drain deadline, and the recommended Server timeout set for real deployments.
- [Server-side render example](/examples/server-side-render) — A multi-page guestbook rendered by Go's html/template. The same SSR pattern that powers this documentation website you are reading now.
- [Static site example](/examples/static-site) — Conditional GET (304 via ETag and Last-Modified) and range requests (206) on top of MuxMaster's ServeFiles primitive. Production static-asset semantics.

