Modern Web Apps using Rust: Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment
By Nira Talvyn
()
About this ebook
This book introduces you to web development with Rust and Leptos. To begin with, you install a solid Rust toolchain and set up Leptos in VS Code, and then you see your first "Hello World" interface rendered via WebAssembly right away. So, first you'll design a microservice-inspired book-selling sample app, called LibroCo
Related to Modern Web Apps using Rust
Related ebooks
Ultimate Full-Stack Web Development with MEVN: Learn From Designing to Deploying Production-Gr7ade Web Applications with MongoDB, Express, Vue, and Node.js on AWS, Azure, and GCP (English Edition) Rating: 0 out of 5 stars0 ratingsLearning Rust Rating: 0 out of 5 stars0 ratingsProgramming Backend with Go Rating: 0 out of 5 stars0 ratingsHands-On Microservices with JavaScript: Build scalable web applications with JavaScript, Node.js, and Docker Rating: 0 out of 5 stars0 ratingsNode.js Cookbook: Practical recipes for building server-side web applications with Node.js 22 Rating: 0 out of 5 stars0 ratingsProjects with IOTA Rating: 0 out of 5 stars0 ratingsWebRTC Blueprints Rating: 0 out of 5 stars0 ratingsFull-Stack Web Development with TypeScript 5: Craft modern full-stack projects with Bun, PostgreSQL, Svelte, TypeScript, and OpenAI Rating: 0 out of 5 stars0 ratingsWebRTC Cookbook Rating: 0 out of 5 stars0 ratingsRust for Embedded Systems Rating: 0 out of 5 stars0 ratingsMastering the Art of Node.js Programming: Unraveling the Secrets of Expert-Level Programming Rating: 0 out of 5 stars0 ratingsModern Web Development: Kickstarting with Svelte Rating: 0 out of 5 stars0 ratingsScientific Computing with Scala Rating: 0 out of 5 stars0 ratingsUltimate Web Authentication Handbook Rating: 0 out of 5 stars0 ratingsRust Essentials: Master the Language of Safe Systems Programming Rating: 0 out of 5 stars0 ratingsGit Repository Management in 30 Days: Learn to manage code repositories like a pro (English Edition) Rating: 0 out of 5 stars0 ratingsElixir Programming: From Basics to Expert Proficiency Rating: 0 out of 5 stars0 ratingsBluetooth Low Energy LE Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsThe JavaScript Journey: From Basics to Full-Stack Mastery Rating: 0 out of 5 stars0 ratingsUltimate Git and GitHub for Modern Software Development Rating: 0 out of 5 stars0 ratings
Internet & Web For You
Canva Tips and Tricks Beyond The Limits Rating: 3 out of 5 stars3/5Social Engineering: The Science of Human Hacking Rating: 3 out of 5 stars3/5The $1,000,000 Web Designer Guide: A Practical Guide for Wealth and Freedom as an Online Freelancer Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Notion for Beginners: Notion for Work, Play, and Productivity Rating: 4 out of 5 stars4/5The Beginner's Affiliate Marketing Blueprint Rating: 4 out of 5 stars4/5Coding For Dummies Rating: 5 out of 5 stars5/5The Digital Marketing Handbook: A Step-By-Step Guide to Creating Websites That Sell Rating: 5 out of 5 stars5/5How to Be Invisible: Protect Your Home, Your Children, Your Assets, and Your Life Rating: 4 out of 5 stars4/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Cybersecurity For Dummies Rating: 5 out of 5 stars5/5More Porn - Faster!: 50 Tips & Tools for Faster and More Efficient Porn Browsing Rating: 3 out of 5 stars3/5Build a WordPress Website From Scratch 2024: WordPress 2024 Rating: 0 out of 5 stars0 ratingsThe Gothic Novel Collection Rating: 5 out of 5 stars5/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/5The Basics of User Experience Design by Interaction Design Foundation Rating: 4 out of 5 stars4/5Get Into UX: A foolproof guide to getting your first user experience job Rating: 4 out of 5 stars4/5UX/UI Design Playbook Rating: 4 out of 5 stars4/5Stop Asking Questions: How to Lead High-Impact Interviews and Learn Anything from Anyone Rating: 5 out of 5 stars5/52022 Adobe® Premiere Pro Guide For Filmmakers and YouTubers Rating: 5 out of 5 stars5/5How to Disappear and Live Off the Grid: A CIA Insider's Guide Rating: 0 out of 5 stars0 ratingsUltimate guide for being anonymous: Avoiding prison time for fun and profit Rating: 5 out of 5 stars5/5Blogging For Dummies Rating: 0 out of 5 stars0 ratingsHow To Make Money Blogging: How I Replaced My Day-Job With My Blog and How You Can Start A Blog Today Rating: 4 out of 5 stars4/5Explain the Cloud Like I’m 10 Rating: 5 out of 5 stars5/5
Reviews for Modern Web Apps using Rust
0 ratings0 reviews
Book preview
Modern Web Apps using Rust - Nira Talvyn
Modern Web Apps using Rust
Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment
Nira Talvyn
Preface
In this book, you'll dive into the world of web development with Rust and Leptos. First, you install a solid Rust toolchain and set up Leptos in VS Code, and then you see your first Hello World
interface rendered via WebAssembly right away. So, first you'll design a microservice-inspired book-selling sample app, called LibroCommerce, into inventory, orders, and user accounts. Then, you'll connect each piece with Axum handlers, SQLx queries, and shared Serde models.
By the time you get to Chapter 3, you'll have built a nonblocking, Tokio-driven server that handles dynamic routes, powers Leptos SSR pages, and secures endpoints with JWT and OAuth2. Then, you add real-time features: WebSockets send stock updates and order-status events to reactive Leptos signals, keeping the UI and backend in sync. As you go, you'll be writing end-to-end Playwright tests and setting up GitHub Actions so that every commit runs Rust tests, Playwright scenarios, Docker builds, and Kubernetes rollouts automatically. You'll learn how to connect to PostgreSQL with an async pool, model Books, Users, and Orders with Serde-annotated Rust structs, and implement CRUD, password hashing with Argon2, encrypted backups, and session stores in Redis. Performance tuning shows you how to optimize Tokio threads, tune SQLx pools, stream large result sets, debounce client inputs, and apply backpressure. At last, you put each microservice and frontend into Docker containers, deploy them with Kubernetes, and then use serverless and edge computing. That means running order logic as AWS Lambda functions and serving SSR pages from Cloudflare Workers. This way, you can cut down on latency for users worldwide.
It's packed with over 100 bite-sized examples and ready-to-run solutions, and it'll walk you through building and operating a production-style web application in Rust, step-by-step. You won't become a Rust language expert, but you'll finish ready to design, code, test, and deploy modern web apps.
In this book you will learn how to:
Start using Rust and Leptos with VS Code to develop web applications using WebAssembly.
Architect microservices with inventory, orders, and user modules for modular, scalable applications.
Make servers that respond to user activity and are not blocked by other users. Use Tokio and Axum with dynamic routing and concurrency.
Employ business logic with SQLX, transactions, and external API integration for real-world workflows.
Protect your devices with JWT, OAuth2, Argon2 password hashing, HttpOnly cookies, and TLS encryption.
Handle database state asynchronously, define Serde data models, and perform efficient CRUD operations.
Utilize WebSockets, Leptos signals, and broadcast channels to enable real-time updates.
Perform end-to-end testing with Playwright, integration tests, and automated CI pipelines for reliability.
Put microservices and the frontend into containers using Docker, and use Kubernetes to orchestrate them so they can be deployed without any downtime.
Take advantage of serverless functions and edge computing to reduce latency and expand globally as needed.
Prologue
We are on the cusp of a new era in web development, where Rust's performance and safety are set to transform the way we build interactive, scalable applications. Just imagine the possibilities of shipping code that runs at near-native speed in the browser, while sharing the same language, types, and crates between client and server! Picture microservices that never block, servers that self-heal under load, and real-time features that flow seamlessly from backend to UI. That future is here, and it begins with this book!
From the very first moment I discovered the incredible potential of Rust for web apps, I saw so much more than just a fast systems language. I saw an incredible unified toolchain that can compile both network services and front-end logic into WebAssembly. I saw Leptos enabling reactive components without a JavaScript runtime, sharing Serde models across every layer. I saw an incredible architecture where inventory, orders, and user accounts live in distinct modules, yet integrate so smoothly that shipping a change feels effortless. I saw the most amazing real-time WebSocket updates driving stock levels and order statuses, incredible end-to-end tests catching regressions before they reach production, and GitHub Actions flipping the switch from code commit to global rollout with no human clicks.
In the chapters ahead, you and I will build LibroCommerce, a sample book-selling application that evolves as you progress. You'll start by setting up Rust, Cargo, and Leptos in VS Code, compiling your first WebAssembly bundle, and watching Hello, LibroCommerce!
light up your browser. You'll design a microservice-inspired architecture, splitting functionality into inventory, orders, and accounts, then connect those modules with Axum handlers and SQLx queries. You'll model data with Serde-annotated structs, implement CRUD operations, and secure every endpoint with JWT, OAuth2, and Argon2-hashed passwords.
Then, we'll add real-time magic—broadcast channels in Tokio, WebSocket endpoints in Axum, and reactive signals in Leptos—so your UI updates instantly when stock changes or an order moves from pending to shipped. You'll get to write Playwright end-to-end tests that spin up headless browsers, place orders, and assert live status updates, all inside your continuous integration pipeline. You'll be thrilled to package each service and the frontend into Docker containers, deploy to Kubernetes with zero-downtime rollouts, and watch as your cluster scales under load. And that's not all — you'll dive into the world of serverless and edge computing, mastering the art of running Rust functions in AWS Lambda and Leptos SSR at Cloudflare Workers. Get ready to take your app to new heights, reaching users worldwide in the blink of an eye!
This book is so much more than a mere collection of examples—it's an exhilarating hands-on journey! You'll get to write over a hundred code snippets, inspect them in VS Code, and see immediate feedback in browser and terminal. You will troubleshoot errors, refine performance with tuned Tokio threads and SQLx pools, and emerge with confidence in building production-grade web apps in Rust. By the time you reach the end, you will have taken that bold first step—from curiosity to creation—and you will be armed with patterns, practices, and working solutions that will let you continue innovating long after you turn the final page. Welcome to Modern Web Apps using Rust.
**Let's dive in!**
Copyright © 2025 by GitforGits
All rights reserved. This book is protected under copyright laws and no part of it may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without the prior written permission of the publisher. Any unauthorized reproduction, distribution, or transmission of this work may result in civil and criminal penalties and will be dealt with in the respective jurisdiction at anywhere in India, in accordance with the applicable copyright laws.
Published by: GitforGits
Publisher: Sonal Dhandre
www.gitforgits.com
Printed in India
First Printing: January 2025
Cover Design by: Kitten Publishing
For permission to use material from this book, please contact GitforGits at [email protected].
Content
Preface
GitforGits
Acknowledgement
Chapter 1: Setting up Rust & Leptos Environment
Overview
Why Rust & Leptos for Web Apps?
Rust’s Emergence in Web
Engine behind Modern Web Apps
Introducing Leptos
Future of Web Development
Installing IDE, Libraries & Other Tools
Installing Rust
Configuring VS Code & Crates
Setting up LibroCommerce Project
Structuring LibroCommerce App
Making First Commit
Establishing Branching
Designing Modular Folder Layout
Building Hello World
Interface
Setting up Project
Writing Leptos Component
Integrating Component into App
Demonstrating Basic Client–Server Communication
Compiling and Running Leptos App
Summary
Chapter 2: Designing Modern Architecture
Overview
Modern Web Concepts
Microservices for Modern Apps
Modern Architecture for better UX
Key Architectural Patterns
Setting Up Modules and Service Boundaries
Creating Modules in Project Structure
Writing Modules
Integrating Modules
Connecting Modules
Visualizing Data Flows and User Journeys
Reviewing Modules and Service Boundaries
Implementing HTTP Handlers for Each Module
Crafting Leptos Components
Mapping End‑to‑end Data Path
Integrating Logging and Monitoring
Adding Tracing Dependencies
Initializing Tracing Subscriber
Instrumenting HTTP Handlers
Adding Logging Inside Handlers and Modules
Capturing and Reporting Errors
Summary
Chapter 3: Building Application Server
Overview
Building Responsive Web Server with Tokio
Dynamic Routing and Concurrent Requests
Implementing Dynamic Routes with Axum
Ensuring Concurrency and Responsiveness
Integrating Leptos for Server‑Driven Pages
Testing and Observing Performance
Implementing Business Logic
Inventory Module: Fetching and Filtering Books
Creating and Managing Orders
Integrating External Payment Gateways
Composing Handlers for Business Logic
Integrating Third-party APIs
Fetching Metadata from OpenLibrary
Defining Data Model
Implementing Metadata Module
Exposing Metadata Endpoint
Integrating Payment Gateways
Consuming Third‑Party Data in Leptos Components
Securing and Logging Requests
Add ‘jsonwebtoken’
Define JWT Claims and Helper
Implement Authentication Middleware
Apply Middleware to Routes
Testing Authentication and Logging
Summary
Chapter 4: Database Integration and State Management
Overview
Connecting App to PostgreSQL
Managing Configuration with Environment Variables
Initializing Asynchronous Connection Pool
Wiring Pool into App State
Using Pool in Handlers
Designing Data Models
Leveraging Serde for Flexible Serialization
Defining Book Model
Defining User Model
Defining Order Model with Enums
Implementing Dynamic CRUD Operations
Defining New and Update DTOs
Implementing CRUD Functions
Exposing CRUD Endpoints
Registering Routes
Verifying CRUD Operations
Setting up Backups and Encryption
Installing Dotenv and Argon2
Managing Configuration Securely
Automating Database Backups
Password Hashing with Argon2
Integrating Hashing
Verifying Passwords on Login
Summary
Chapter 5: Modern Interactions with REST, GraphQL, and OAuth
Overview
Crafting RESTful Endpoints
Exposing Book Resources
Implementing Order Endpoints
Registering Routes in main.rs
Testing RESTful Interfaces
Extending API Flexibility
Defining GraphQL Types and Schema
Mounting GraphQL and GraphiQL Endpoints
Testing GraphQL Queries
Implementing OAuth and Token-Based Authentication
Configuring OAuth2 with Environment Variables
Setting up OAuth2 Client
Redirecting Users to