axum-wire
Server-driven reactive UI components for Axum — like Laravel Livewire, but for Rust.
Components are Rust structs. State lives on the server. User interactions (clicks, input, form submissions) trigger server actions via AJAX — the server re-renders and morphdom patches the DOM in-place. No full page reloads, no client-side framework, no WASM.
Quick start
[]
= "0.0.1"
= "0.8"
= { = "1", = ["derive"] }
= { = "1", = ["full"] }
use ;
use ;
async
Features
wire:click— call Rust methods from clicks, type-checked with{Self::method}wire:model— two-way bind inputs to struct fields (.livefor instant sync)wire:submit— handle forms server-sidewire:poll— auto-refresh on an intervalwire:navigate— SPA-like page transitions with prefetch on hoverwire:loading— show elements during server round-tripswire:ignore— preserve DOM subtrees across re-renderswire:init— call an action on mounthtml!— JSX-like macro with<Counter />sub-components and compile-time type checkingself.js()— dispatch JavaScript from server actions ($wireavailable in scope)self.redirect()/self.redirect_navigate()— server-side redirectsself.skip_render()/#[renderless]— skip re-rendering for lightweight actions- Async
render()&mount()— query databases or call APIs directly - Layouts — per-route layout overrides via
.wire_with() - Sub-components —
<Counter count=42 />with type-checked props - Alpine.js — ships by default,
$wiremagic for client-side reactivity - Hot reload — subsecond integration, auto-detected under
dx serve
How it works
- Server renders the component to HTML. State is serialized as a JSON snapshot in a
data-wire-snapshotattribute. - User interacts — clicks, types, submits. A small JS runtime intercepts the event.
- AJAX POST sends the snapshot + action name to
/_wire/update. - Server deserializes the snapshot, calls the action method, re-renders, returns new HTML + snapshot.
- morphdom diffs the new HTML in-place. No flicker, no full reload.
Layouts
let app = new
.layout // default layout
.wire
.wire_with // per-route override
.into_router;
A layout is a Fn(LayoutContext) -> String that receives body (component HTML), wire_js (the runtime scripts), and component (the wire name).
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.