What We’re Building
A full-featured todo app with:- List all todos
- Create new todos
- Mark todos as complete
- Edit and delete todos
- All without writing a single API endpoint
Prerequisites
Step 1: Create the Migration
Step 2: Create the Controller
src/controllers/todos.rs:
Step 3: Define Routes
Editsrc/routes.rs:
Step 4: Generate TypeScript Types
Props Types (frontend/src/types/inertia-props.ts)
Route Types (frontend/src/types/routes.ts)
Step 5: Create React Components
Index Page
Createfrontend/src/pages/Todos/Index.tsx:
Create Page
Createfrontend/src/pages/Todos/Create.tsx:
Edit Page
Createfrontend/src/pages/Todos/Edit.tsx:
Step 6: Run the App
Start the development server:http://localhost:8080/todos to see your todo app in action!
How It Works
- No API Layer: The Rust backend returns Inertia responses directly to React components
- End-to-End Type Safety: TypeScript types are generated from Rust structs for both props AND routes
- Type-Safe Routes: No magic strings -
controllers.todos.toggle({ id })instead of'/todos/${id}/toggle' - SPA Navigation: Page transitions happen without full page reloads
- Forms:
<Form>component accepts route objects directly (Inertia v2+UrlMethodPaircompatible) - Redirects: After mutations, redirect to update the UI
Key Inertia Features Used
| Feature | Description |
|---|---|
inertia_response! | Return page with props |
redirect() | Navigate after mutations |
<Link href={controllers.x.y()}> | Type-safe SPA navigation |
<Form action={controllers.x.y()}> | Type-safe declarative form handling |
router.visit(controllers.x.y()) | Type-safe programmatic navigation |
controllers object | Generated type-safe route helpers |
Summary
You’ve built a complete CRUD application with end-to-end type safety:- Database migrations and models
- Server-side controllers with Inertia responses
- React pages with type-safe props
- Type-safe routes with
controllersobject (no magic strings!) - Forms with
<Form>component and validation feedback - Type-safe navigation
Next Steps
- Add user authentication
- Implement optimistic updates
- Add toast notifications
- Deploy to production