
Axum WebSockets With Broadcast Channels as a Weekend Project
Build a chat room over WebSockets in Axum 0.8, using a Tokio broadcast channel to fan messages out, two tasks per socket, size limits and an integration test that drives real clients.
Tag
21 posts

Build a chat room over WebSockets in Axum 0.8, using a Tokio broadcast channel to fan messages out, two tasks per socket, size limits and an integration test that drives real clients.

Limit requests per client in Axum with a small middleware, then see when to switch to tower_governor or a Redis counter. Includes fixed windows, token buckets and 429 responses.

Protect an Axum service from slow and oversized requests: TimeoutLayer, DefaultBodyLimit, header limits and what a reverse proxy should add on top.

Handle HTML forms and multipart file uploads in Axum 0.8: Form, Multipart, size limits, content type checks, safe filenames and streaming to disk.

Add behavior around every request with Tower layers, or write your own with axum middleware from_fn. See the order layers run in and when to pick each form.

Share a pool, config and caches with Axum's State extractor. Learn why the state must be Clone, when to use Arc and how to mutate shared data safely.

Handler arguments in Axum are extractors that run in order, and only the last one may consume the request body. Learn the rule and the error it prevents.

Axum routes map a path and method to an async function. Learn path parameters, nesting, fallbacks and the 0.8 syntax change for captures.

Build a small Axum 0.8 service from an empty crate to something you can deploy: a testable router, one error type, limits and timeouts, tracing, oneshot tests and graceful shutdown on SIGTERM.