Veer
The Inertia.js server-side protocol superset, for Rust.
Build modern single-page apps in React, Vue, or Svelte β without writing a JSON API, a client-side router, or a single fetch. Your Rust handlers return typed props, and the frontend hydrates as if the page was server-rendered. Because it was.
π Table of Contents
- β¨ What is Inertia, and why a Rust adapter
- π¦ Installation
- π Quick Start
- π³ Cookbook
- ποΈ Feature Flags
- ποΈ Architecture
- β οΈ Caveats
- π§ͺ Example App
- πΊοΈ Status & Roadmap
- π Acknowledgements
- π§ͺ Testing
- π Changelog
- π€ Contributing
- π Security Vulnerabilities
- π Support This Project
- β Star History
- π License
β¨ What is Inertia, and why a Rust adapter
Inertia.js is a glue layer that lets a classic server-rendered backend drive a modern SPA frontend. The server returns a page object (component name + props); the official Inertia client adapter for React/Vue/Svelte takes care of mounting the component, hydrating props, intercepting links, and making subsequent navigations into JSON XHRs.
veer is a clean-room Rust implementation of the server side of the Inertia v3 protocol. It targets axum out of the box; the protocol core is framework-agnostic, so adapters for other Rust web frameworks slot in beside it.
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β Rust handler β ββ page object βββΆ β Inertia client (JS) β
β inertia.render(...) β (JSON) β React / Vue / Svelte β
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β² β
ββββββββββββββ navigation XHR ββββββββββββββββββββ
Highlights
- π¦ Pure Rust server-side implementation of Inertia v3
- β‘ First-class axum adapter (extractor + tower layer)
- π§© Framework-agnostic protocol core β drop new adapters in beside the axum one
- π¦ Partial reloads, deferred props, merge props, encrypted/clear history
- π₯οΈ SSR via
@inertiajs/server(Node or Bun) with graceful fallback - βοΈ Vite dev + production manifest integration that mirrors Laravel's
@vite - π€ File uploads via typed
InertiaForm+ a streamingMultipartStreamextractor - β
Validation flash for
validatorandgarde, plus a cookie-based session store - πͺ’ End-to-end TypeScript bindings: typed page props + Ziggy-style route helpers, generated from Rust
π¦ Installation
Add veer to your Cargo.toml:
[]
= "0.1"
Or with cargo add:
The default feature set includes the axum adapter. See Feature flags for everything else.
π Quick Start
use ;
use ;
async
The Inertia extractor reads the request. render(component, props) returns a builder. The layer handles the rest of the protocol β initial HTML on first load, JSON on XHR navigations, 409 for asset-version mismatches, 303 for POST-redirects, version checks, partial reloads.
π³ Cookbook
async
InertiaForm accepts application/json, application/x-www-form-urlencoded, and (with the multipart feature) multipart/form-data. The same handler works regardless of how the Inertia client serialized the request.
On the frontend, usePage().props.errors and usePage().props.flash are auto-populated whenever a SessionStore is configured β no extra wiring.
Enable the multipart feature and add UploadedFile fields to your typed struct:
use ;
async
Inertia's useForm automatically switches to multipart/form-data when any field is a File or Blob. The same handler accepts JSON when no file is attached and multipart when one is β no separate route required.
For large or unbounded uploads where in-memory buffering isn't acceptable, use MultipartStream instead:
use MultipartStream;
async
async
Returns 409 + X-Inertia-Location. The Inertia client honors this with a hard navigation.
inertia
.render
.lazy
.deferred
.merge
| Method | Behavior |
|---|---|
lazy(key, closure) (alias optional) |
Closure only runs when the client requests this key via a partial reload |
deferred(key, group, closure) |
First response advertises the key under deferredProps[group]; client then issues a follow-up reload that resolves it |
merge(key) |
Marks the key so the client merges the value into existing state instead of replacing |
encrypt_history() / clear_history() |
Set the Inertia v2+ history-state primitives |
no_ssr() |
Skip SSR for this response only |
use shared_props_fn;
let cfg = new
.shared;
Shared props merge under per-response props (handler props win on key collision).
Enable the ssr feature and point at the SSR service:
use HttpSsrClient;
let cfg = new
.ssr;
SSR failures fall back to client-side rendering by default. Set ssr_required(true) for hard-fail behavior.
For end-to-end SSR you'll usually combine this with ViteRootView (next entry) β ViteRootView inlines the SSR body verbatim and emits the <script data-page> mount the Inertia v3 client expects.
ViteRootView is a drop-in RootView that mirrors what Laravel's @vite + @viteReactRefresh Blade directives do. Two modes:
Dev β cross-origin script tags pointing at the Vite dev server, plus (opt-in) the React refresh preamble required when the HTML shell is served off-origin:
use ViteRootView;
let cfg = new
.root_view;
Production β vite build writes dist/.vite/manifest.json. ViteRootView::production walks it from the entry, emitting the entry script, its CSS, and <link rel="modulepreload"> hints for transitively imported chunks:
use ;
let manifest = load?;
let version = manifest.hash; // changes whenever any chunk hash changes
let cfg = new
.version // bumps client asset cache on rebuild
.root_view;
// Serve the built bundle next to the routes:
// .nest_service("/build", tower_http::services::ServeDir::new("dist"))
Wiring version to manifest.hash() means any rebuild auto-invalidates clients via the Inertia 409 + force-reload protocol β no manual version bumps.
For SSR in production, build the sidecar with vite build --ssr frontend/ssr.tsx and run the resulting bundle (bun dist/ssr/ssr.js or node β¦). Same :13714/render interface as dev.
Enable the ts feature and the frontend gets an auto-generated gen/ directory containing every page's props type, a discriminated Pages union, and one TypeScript module per controller with method-aware URL builders.
[]
= { = "0.1", = ["ts"] }
= "10"
Annotate each prop struct and register it as a page:
use Serialize;
use TS;
register_page!;
Then build your router using veer::Router β same fluent API as axum::Router, but every route gets a name and method so the codegen knows about it:
use *;
// In main():
let app = router.build.with_state.layer;
build() returns a regular axum::Router, so .with_state / .layer / .merge / anything else just works. Same-path multi-method calls (GET + POST on /users) are merged into a single MethodRouter automatically β no panic on duplicate paths.
ts-rs mirrors #[serde(rename_all)] into the generated TypeScript, so the same struct drives both wire format and type. Route names follow the Laravel resource convention (index/show/create/store/update/destroy) so they don't collide with JavaScript reserved words.
Add a tiny binary that builds the router (so the runtime route registry populates) and then emits the bundle. Drop this in src/bin/gen-bindings.rs inside your app crate β cargo auto-discovers it:
// src/bin/gen-bindings.rs
Generate with:
The codegen has to run inside your app binary (not a standalone CLI), because the route registry is populated at runtime by Router::build() and the page registrations are link-time inventory submissions β both only exist in your compiled crate.
On the frontend, import types and the per-controller action module:
import { usePage, router, Link } from "@inertiajs/react";
import { users, type UsersIndexProps } from "./gen";
export default function Index() {
const { props } = usePage<UsersIndexProps>();
return (
<>
<Link href={users.create.url()}>New user</Link>
{props.users.map((u) => (
<Link key={u.id} href={users.show.url({ id: u.id })}>{u.name}</Link>
))}
</>
);
}
Each action is a callable with .url and .form helpers:
| Call | Returns |
|---|---|
users.show({id: 1}) |
{ url: "/users/1", method: "get" } as const (visit definition) |
users.show.url({id: 1}) |
"/users/1" (just the path string) |
users.show.form({id: 1}) |
{ action: "/users/1", method: "get" } as const (props for <form>) |
Generated layout:
frontend/gen/
index.ts protocol types, Pages, prop types, action namespace re-exports
actions/
users.ts export const index, show, create, store, update, destroy
posts.ts β¦
_root.ts routes without a dotted prefix
Always<T> and Merge<T> collapse to T on the TypeScript side β the protocol's mergeProps / deferredProps arrays in the envelope carry the marker information instead.
Customize the output layout with the Split builder β rename the actions/ subdirectory, add a filename prefix/suffix, or flatten everything into the root:
new
.actions_dir // -> frontend/gen/controllers/
.file_suffix // -> users-controller.ts, posts-controller.ts
.generate?;
actions_dir("") writes the controller files directly alongside index.ts; file_prefix is similarly available.
Need a single bundled file instead of the split tree? Use bindings::generate("./frontend/inertia.gen.ts") β same content, one file, with the route tree exposed as a nested routes.users.show(...) namespace.
Auto-regenerate on commit with lefthook. Add this to lefthook.yml at the repo root:
pre-commit:
commands:
veer-bindings:
glob: "*.rs"
run: cargo run -q --bin gen-bindings
stage_fixed: true
stage_fixed: true re-adds the regenerated TS files to the commit so they never drift from the Rust source. Run lefthook install once per dev machine. Pair with a CI job that runs cargo run --bin gen-bindings && git diff --exit-code on PRs to fail-fast if someone bypasses the hook.
For apps without an existing session crate:
use CookieSessionStore;
let cfg = new
.session;
HMAC-SHA256-signed, constant-time verification, one-shot semantics. For anything more elaborate, implement the SessionStore trait over your existing session crate (axum-login, redis, β¦) in ~30 lines.
If the app already runs tower-sessions, enable the tower-sessions feature and plug TowerSessionStore into the config. Flash data round-trips through whatever backend (Redis, Postgres, in-memory, β¦) tower-sessions is configured with.
use Duration;
use ;
use ;
let session_layer = new
.with_expiry;
let cfg = new.session;
let app = new
// β¦ routes β¦
.layer
.layer; // tower-sessions must wrap *outside* InertiaLayer
Flash is stored under a single key (_veer_flash by default; override with TowerSessionStore::new().key("...")).
ποΈ Feature Flags
| Flag | Default | Effect |
|---|---|---|
axum |
on | Axum extractor + tower layer + InertiaForm body extractor |
multipart |
off | File upload support (UploadedFile, MultipartStream) |
ssr |
off | HTTP SSR client (reqwest) |
cookie-session |
off | Signed-cookie one-shot flash store |
tower-sessions |
off | Flash store backed by tower-sessions |
validator |
off | IntoErrorBag impl for validator::ValidationErrors |
garde |
off | IntoErrorBag impl for garde::Report |
ts |
off | End-to-end TypeScript bindings codegen (ts-rs + inventory) |
Disabling a feature drops its transitive deps entirely.
ποΈ Architecture
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β axum Router β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β InertiaLayer β β
β β ββ reads flash from SessionStore β β
β β ββ injects config into request extensions β β
β β ββ on response: finalizes InertiaResponse, β β
β β writes flash, rewrites 302β303 on non-GET β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββ β
β β Inertia (extractor) β β
β β inertia.render(...) β β β
β β InertiaResponse builder β β
β βββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββ
β Protocol core (framework-agnostic) β
β β’ RequestInfo / PageObject β
β β’ decide() state machine β
β β’ prop resolver (partial reloads, β
β deferred groups, merge keys) β
β β’ Pluggable: RootView, SessionStore,β
β SsrClient, SharedProps β
ββββββββββββββββββββββββββββββββββββββββ
The protocol core has zero I/O and zero framework deps β pure data structures and decision functions, exhaustively unit-tested. Adapters for other Rust frameworks (actix, rocket, salvo) can sit beside the axum one without touching it.
β οΈ Caveats
Always<T>andMerge<T>are detected at any depth and through any serialization path β typed#[derive(Serialize)]structs,serde_json::json!, hand-builtValues, mixed maps. Only top-level matches affect the Inertia wire format though, because the protocol has no notion of a "nested merge prop". Wrappers placed deeper are still stripped from the JSON sent to the client; they just don't appear inmergeProps.
π§ͺ Example App
A complete end-to-end demo lives at examples/axum-react-todo/ β axum backend + React/Vite frontend, with validation, flash messages, and an in-memory todo store.
# Terminal 1 β Rust backend
# Terminal 2 β Vite dev server
πΊοΈ Status & Roadmap
veer is pre-1.0. The v0.1 protocol surface is complete (all Inertia v3 features: partial reloads, deferred props, merge props, encrypted/clear history, SSR, asset versioning, validation flash). Planned for follow-ups:
- Adapters for
actix-webandrocket - Typed route-param inference (today:
string | number; goal: read each handler'sPathextractor and emit the matching TS type)
Contributions, bug reports, and protocol-conformance fixtures welcome.
π Acknowledgements
The protocol is Inertia.js by Jonathan Reinink and contributors. veer is an independent server-side implementation for Rust, modeled on the Laravel adapter's behavior.
π§ͺ Testing
π Changelog
Please see CHANGELOG for more information on what has changed recently.
π€ Contributing
Please see CONTRIBUTING for details. You can also join our Discord server to discuss ideas and get help: Discord Invite.
π Security Vulnerabilities
Please report security vulnerabilities to security@climactic.co.
π Support This Project
Veer is free and open source, built and maintained with care. If this crate has saved you development time or helped power your application, please consider supporting its continued development.
π Sponsors
Your logo here β Become a sponsor and get your logo featured in this README and on our website.
Interested in title sponsorship? Contact us at sponsors@climactic.co for premium placement and recognition.
β Star History
π License
Dual-licensed under MIT or Apache 2.0 at your option. Please see MIT and APACHE for more information.