Explore 1.5M+ audiobooks & ebooks free for days

Only $12.99 CAD/month after trial. Cancel anytime.

Modern Web Apps using Rust: Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment
Modern Web Apps using Rust: Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment
Modern Web Apps using Rust: Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment
Ebook236 pages3 hours

Modern Web Apps using Rust: Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment

Rating: 0 out of 5 stars

()

Read preview

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

LanguageEnglish
PublisherGitforGits
Release dateJan 25, 2025
ISBN9789349174986
Modern Web Apps using Rust: Build full-stack applications using Rust-based Leptos framework, GraphQL, WebAssembly, and cloud-native deployment

Related to Modern Web Apps using Rust

Related ebooks

Internet & Web For You

View More

Reviews for Modern Web Apps using Rust

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    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

    [email protected]

    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

    Enjoying the preview?
    Page 1 of 1