MARY.WIN

RUSTY — INERTIA — INTRODUCTION

Introduction

The introduction to Inertia on Rust, draft chapters on the Inertia adapter for Rust.

Inertia lets an application keep its server-side routes and handlers and still build its pages in React, Vue or Svelte, with no JSON API between the two. inertia-laravel-rust is the server half of that arrangement for Rust. In this introduction we'll define the words the chapters lean on (Inertia, page component, props, page object, adapter, struct, handler) and look at one handler from the crate's own example.

This introduction covers vocabulary and one listing. It does not cover installing the crate or setting up a React build. It assumes you have written, in some server framework, a route that returns a view.

What Is Inertia?

The link to /invoices/8 expected what links had always gotten, which was a new document. It was an anchor with an href, and that was all it knew about itself. The click never reached the browser's navigation. A script took it, sent the request with one extra header, and received a few lines of JSON and no document at all.

Sometimes you want React for the page and your server's routing, handlers and middleware for everything else, and the usual price is a JSON API that you design, version and keep in step with both sides. Thankfully, there's an arrangement without one. Inertia is a client-side library, and a protocol between that library and your server, in which the server answers a page visit with the name of a JavaScript component and the data for it.¹

Full definition Inertia
Kind
A client-side routing library, and the protocol it speaks with a server.
Parts
Two parts. The client library runs in the browser. An adapter implements the protocol on the server.
Behavior
Answers a page visit with the name of a page component and its props, in place of a server-rendered view.
Boundary
Not a JSON API that you design. The server keeps its routes, handlers and middleware, and the protocol fixes the shape of the response.
Instance
A visit to /invoices/7 carrying X-Inertia: true gets back a page object whose component is Invoices/Show.
Analogue
Returning a Blade view from a controller, except the view is a JavaScript component and its data arrives as JSON. This comparison is the author's.

Inertia in the glossary

Three terms come with it:

  • A page component is a React, Vue or Svelte component that is a whole page. The server refers to it by a string, such as Invoices/Show.
  • Props are the data the server sends to that component.
  • A page object is the JSON that describes one page. Take a look at Example 0-1.

Example 0-1. A page object, trimmed to its four required fields

{"component":"Invoices/Show","props":{"invoiceId":7},"url":"/invoices/7","version":"1"}

There are four pieces here. component names the page component. props is its data. url is the page's address. version identifies the current build of your JavaScript and CSS; Chapter 7 covers what happens when it changes. A page object from this crate carries more than these four, and the chapters introduce each extra field where it is used.

Full definition Page component
Kind
A React, Vue or Svelte component.
Behavior
Renders one whole page from the props it is given.
Boundary
Not a layout or a partial. A page object names exactly one page component.
Instance
Invoices/Show.
Analogue
A Blade view file, except it runs in the browser. This comparison is the author's.

Page component in the glossary

Full definition Props
Kind
A JSON object, held in the page object's props field.
Behavior
Carries data from a handler to a page component.
Boundary
Not component state. Props come from the server with each visit.
Instance
{"invoiceId":7}.
Analogue
The array passed as the second argument to view() in Laravel. This comparison is the author's.

Props in the glossary

Full definition Page object
Kind
A JSON object.
Parts
Four required fields: component, props, url and version. Other fields appear only when they apply.
Behavior
Tells the client which page component to show and what data to give it.
Boundary
Not an API resource. It describes a page, not a record.
Instance
{"component":"Invoices/Show","props":{"invoiceId":7},"url":"/invoices/7","version":"1"}, trimmed to the required fields.

Page object in the glossary

A browser's first visit to an Inertia application is an ordinary request, and the answer is a full HTML document with the page object inside it, in a <script type="application/json"> element. Every visit after that is made by the Inertia client, which adds the header X-Inertia: true, and the server answers with the page object alone. The client then swaps one page component for another without reloading the document.

What Is an Adapter?

The protocol is not tied to one server framework. Any backend that speaks HTTP can implement it, and the Laravel adapter is the reference implementation. An adapter is the server-side library that does the implementing: it decides whether a request gets a document or JSON, builds the page object, and applies the protocol's rules for redirects and versions.

Full definition Adapter
Kind
A server-side library that implements the Inertia protocol.
Behavior
Decides whether a request gets an HTML document or JSON, builds the page object, and applies the protocol's rules for redirects and versions.
Boundary
Not the Inertia client. The client runs in the browser; the adapter runs on the server.
Instance
inertia-laravel-rust for Rust. The Laravel adapter is the reference implementation.

Adapter in the glossary

inertia-laravel-rust is an adapter for Rust. Its core depends on no web framework, and a feature named axum connects it to Axum, the web framework the listings in these chapters use. It ships as a crate, the unit of code the Rust compiler compiles at a time; a library you depend on is a crate. Your code imports this one as inertia, whatever the package is called.

Full definition Crate
Kind
Rust's compilation unit: the smallest amount of code the compiler considers at a time.
Parts
Two forms: a binary crate, which is a program, and a library crate, which other code depends on.
Behavior
Compiles as one unit.
Boundary
Not a package. A package is a bundle of one or more crates that Cargo builds and shares.
Instance
inertia-laravel-rust is a library crate that your code imports as inertia.
Analogue
A Composer package, loosely. This comparison is the author's.

Crate in the glossary

What Is a Struct?

Chapter 1 has the word in its title, so here it is. A struct is a Rust type that groups several named values. Each value is a field, and each field has its own type. Example 0-2 defines a struct and then makes one.

Example 0-2. A struct and an instance of it

struct Invoice {
    id: u64,
    total_cents: i64,
}

let invoice = Invoice { id: 7, total_cents: 1200 };

There are two pieces here. The first block is the definition: the keyword struct, a name, and the fields with their types. The last line is an instance, with a value for every field. If you write PHP, I'd read a struct as a class with typed public properties and no methods.

Full definition Struct
Kind
A Rust type, defined with the keyword struct.
Parts
Named fields, each with its own type. The definition fixes how many.
Behavior
Groups related values under one name.
Boundary
Not a tuple. A tuple's values are told apart by position; a struct's values are named.
Instance
Invoice { id: 7, total_cents: 1200 }.
Analogue
A PHP class with typed public properties and no methods. This comparison is the author's.

Struct in the glossary

A struct matters to these chapters because it can become JSON. The crate serde does that conversion, and the line #[derive(Serialize)] above a struct asks serde to generate the code for it. Chapter 1 puts that line on a struct and hands the struct to a page as its props.

One Handler

A handler is the function a route calls. If you write Laravel, I'd read it as a controller method. Example 0-3 is the handler from the crate's quick start.

Example 0-3. A handler that renders a page

async fn home(inertia: Inertia) -> inertia::Response {
    inertia.render("Home", props! { "greeting" => "Hello from Rust" })
}

There are three new pieces here. The parameter inertia: Inertia is a handle for the current request, which the Axum adapter supplies. render takes the name of a page component and its props. props! is a macro that builds props from pairs of a key and a value.

Full definition Handler
Kind
A function that a route calls.
Behavior
Returns the response for one request.
Boundary
Not middleware. Middleware runs around a handler; Chapter 2 shares props from one.
Instance
home in the crate's quick start, which returns inertia.render("Home", ...).
Analogue
A Laravel controller method. This comparison is the author's.

Handler in the glossary

As you can see, the handler doesn't ask which kind of visit it is answering. The same three lines produce the HTML document for a first visit and the JSON for every visit after it.

How to Read the Chapters

Each chapter takes one mechanism, says at the top what it covers and what it leaves out, and numbers its listings. Each one ends with a test, a summary, and a list of its sources with the file and lines to look at. All of them were written against one commit of the crate, 3ccc126.

If you're unsure where to start, I'd read Chapter 1 and Chapter 2 in order and take the rest as you need them.

TL;DR

Inertia is a client-side library and a protocol: the server answers a visit with a page object, which names a page component and carries its props. The first visit gets an HTML document with the page object inside it, and later visits, marked by X-Inertia: true, get the page object as JSON. An adapter implements the server side, and inertia-laravel-rust is one for Rust with a connection to Axum. A struct is a Rust type with named, typed fields, and a handler is the function a route calls.

¹ Inertia's own documentation describes the server's routing, controllers and middleware as staying where they are, with JavaScript page components taking the place of the server-side view layer.

The sources.

Each line is a claim this chapter makes and where to look. Checked on 2026-11-29 against inertia-laravel-rust at commit 3ccc126.

CLAIM × WHERE — 17
  • Inertia is a client-side routing library; the server keeps routing, controllers and middleware; JavaScript page components replace the server-side view layerI2 · whole page
  • For an Inertia visit the server returns JSON with the component name and props, and the client swaps the page component and updates historyI2 · whole page
  • A page object requires component, props, url and versionI3 · page object fields
  • A first visit gets a full HTML document with the page object in a script type="application/json" elementI3 · first-visit HTML
  • The client sends X-Inertia: true on every Inertia requestI3 and R1 · request headers; src/header.rs L6
  • The protocol is framework-agnostic and the Laravel adapter is the reference implementationI3 · opening section
  • The crate's core is framework-agnostic and the axum feature supplies an Axum adapterR1 · src/lib.rs L7-L10; Cargo.toml L20-L21
  • Code imports the crate as inertia whatever the package is calledR1 · Cargo.toml L14-L16
  • A struct groups named values called fields, each with a type, and is defined with the struct keywordB1 · Defining and Instantiating Structs
  • Example 0-2 is valid Rustmodelled on the Rust Book's User example; not compiled
  • serde's derive macro generates Serialize implementations for a structS1 · Using derive, first paragraph
  • Example 0-3 is the home handler from the crate's quick startR1 · examples/quick_start.rs L9-L11
  • render takes a component name and propsR1 · src/inertia.rs L95
  • The same handler answers a browser visit and an X-Inertia requestR1 · examples/quick_start.rs L1-L2
  • Example 0-1 shows only the four required fields; a real page object from the crate has moreillustrative JSON, not output from the crate
  • A struct read as a PHP class with typed public properties, and a handler read as a controller methodthe author's comparison, not a sourced claim
  • A crate is the smallest amount of code the Rust compiler considers at a time; a package bundles one or more cratesB2 · Packages and Crates, opening paragraphs

I2: Inertia.js v3 documentation, How It Works, read 2026-11-29
I3: Inertia.js v3 documentation, The Protocol, read 2026-11-29
R1: inertiajs/inertia-laravel-rust @3ccc126a24c8fb5bddb140876a1825292c0d216c
B1: The Rust Programming Language, ch. 5.1, Defining and Instantiating Structs, read 2026-11-29
S1: Serde documentation, Using derive, read 2026-11-29
B2: The Rust Programming Language, ch. 7.1, Packages and Crates, read 2026-11-29