Beginning Axum - Learning Modern Web Development With Rust (for memsa memsa) (Indo Yoon)(Z-Library)
rust
No Description
9
Views
0
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
Indo Yoon Beginning Axum Learning Modern Web Development With Rust
Page
3
Indo Yoon Seoul, Korea (Republic of) ISBN 979-8-8688-2630-6 e-ISBN 979-8-8688-2631-3 https://doi.org/10.1007/979-8-8688-2631-3 © Indo Yoon 2026 This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, New York, NY 10004. Phone 1-800-
Page
4
SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm. comwww. springeronline. com, or visit . Apress Media, LLC is a Delaware LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.This Apress imprint is published by the registered company APress Media, LLC, part of Springer Nature. The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
Page
5
Introduction This book introduces Axum, a modern Rust web framework. Through practical code examples, you'll learn to build production-ready backend applications—from basic routing and database integration to middleware and real-time WebSocket communication. Whether you're new to Rust or an experienced developer exploring new frameworks, this book provides a hands-on path to mastering Axum.
Page
6
About This Book This book covers Axum, a Rust backend framework. Axum is developed by the Tokio project, Rust’s most prominent project, and is the fastest-growing Rust framework. Currently, no books specifically focus on the Axum framework, either domestically or internationally. We wrote this book to promote Axum, which has tremendous growth potential, and to help more people adopt it. We explain Axum’s unique user-friendly approach through actual code examples. We’ve focused on features essential in real-world development and structured the book so you can build a complete backend application simply by following along. We provide concise explanations of Rust programming basics and backend technologies while covering each functional component in detail, helping you naturally understand Axum’s architecture. Through this book, we hope you’ll fully experience the appeal of Rust and Axum, and we look forward to seeing many more projects adopt this powerful combination. Target Audience This book will be especially helpful for the following readers. Readers Who Want to Learn Rust If you want to learn Rust through this book, you’ll master core concepts and important syntax in each chapter. We cover many examples where you can actually apply each concept, giving you an opportunity to learn Rust quickly. Readers Who Want to Try a New Project If you’ve learned Rust and want to create your own project, especially web- related projects, this book is ideal. Since Axum actively utilizes Rust’s strength in asynchronous programming, you’ll get an opportunity to learn new things while reviewing Rust’s core concepts.
Page
7
Readers Who Want to Write a High-Performance Web Server This book covers various practical techniques including database configuration, middleware construction, and implementing Server-Sent Event (SSE) endpoints. Whether you’re building high-performance servers for work or side projects, this book will help you achieve your goals more quickly. Prerequisites We recommend having some background knowledge of Rust to read this book, though it’s not required. For readers encountering this content for the first time, we’ve included brief background information and related explanations at the beginning of each chapter. For Rust basics, familiarity with the following concepts is helpful. If you’re new to Rust, we recommend first studying Learning Rust by Comparing with Python (J-Pub, 2024), which clearly explains Rust’s fundamental syntax and concepts. Ownership: Ownership transfer/borrowing, references Asynchronous programming: Arc, Mutex, async/await (tokio knowledge is helpful but not required) Other: Structs, closures For backend server fundamentals, understanding the following is helpful. Don’t worry if you’re unfamiliar—we’ve included plenty of examples and detailed explanations to help you understand easily. Relational Database Management System (RDBMS): This book uses PostgreSQL. Experience with other relational databases (MySQL, MariaDB, etc.) transfers easily. SQL: Basic queries for table definition, data retrieval, and modification. HTTP: Concepts like query parameters, path parameters, and request bodies needed for REST API design.
Page
8
Book Structure Each chapter covers the following: Chapter 1: Introduces Rust backend development characteristics and performs environment setup for practice exercises. Chapter 2: Examines Axum’s core components—routing HTTP requests, processing query parameters and JSON bodies through Extractors, and sharing state across the app through State. Chapter 3: Integrates PostgreSQL with SeaORM, explores schema and migration management, completes all necessary endpoints, and modularizes the project. Chapter 4: Examines tower middleware essentials like logging, timeouts, and authentication and applies them to the application. Chapter 5: Explores WebSocket, a protocol for real-time bidirectional communication between clients and servers, and implements single- connection and multi-connection WebSocket handlers. Chapter 6: Builds a complete chat service project with SSE-based real- time messaging, a React frontend, automated testing, and Docker deployment. The book is structured for easy follow-along with code and screenshots. All code is available on GitHub. If you encounter problems or have questions, please use the repository’s Discussion section. Example code can be found at REST API example: https://github.com/Indosaram/axum- book-code Chat service example: https://github.com/Indosaram/axum-react-chat-app The Docker image built in Chapter 6 is available at https://hub.docker.com/repository/docker/indosar am/axum-chat-app/general.
Page
9
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub. For more detailed information, please visit https:// www. apress. com/ gp/ services/ source-code.
Page
10
Acknowledgments I am deeply grateful to my wife for her unwavering support and patience throughout the writing of this book. The countless late nights and weekends I spent at my desk were made possible only by her understanding, encouragement, and the extra responsibilities she quietly shouldered at home. This book would not exist without her.
Page
11
Table of Contents Chapter 1: Rust and Server Development 1. 1. Why Rust? 1. 1. 1. Advantages of Rust 1. 1. 2. Advantages of Developing Backends with Rust 1. 2. Rust Server Development Case Studies 1. 2. 1. Figma 1. 2. 2. Discord 1. 2. 3. Dropbox 1. 2. 4. npm 1. 3. Comparing Rust Backend Frameworks 1. 3. 1. Why You Should Use Axum 1. 4. Setting Up the Development Environment 1. 4. 1. Installing the Rust Toolchain 1. 4. 2. Installing and Setting Up Visual Studio Code 1. 4. 3. Creating a Project 1. 4. 4. Installing the PostgreSQL Database 1. 4. 5. Installing DBeaver 1. 4. 6. Installing API Testing Tools 1. 5. Reviewing Rust Core Concepts 1. 5. 1. Ownership 1. 5. 2. Ownership of Values 1. 5. 3. Returning Ownership 1. 5. 4. References and Borrowing Ownership
Page
12
1. 5. 5. Mutable References 1. 5. 6. Crates 1. 5. 7. Modules 1. 5. 8. Using Modules 1. 5. 9. Packages 1. 5. 10. Traits 1. 5. 11. Multithreading and Asynchronous Programming 1. 6. Review 1. 7. Quiz References Chapter 2: Exploring Axum Fundamentals 2. 1. HTTP Fundamentals 2. 2. Creating an Axum Project 2. 3. Routers and Handlers 2. 3. 1. Defining Routers 2. 3. 2. Defining Handlers 2. 3. 3. Sending Responses from Handlers 2. 3. 4. Status Codes and Headers 2. 4. State Management 2. 4. 1. State 2. 4. 2. Extension 2. 5. Handler Debugging 2. 6. Example: Creating a Proxy Server 2. 7. Review
Page
13
Chapter 3: Database Integration with SeaORM 3. 1. What Is ORM? 3. 1. 1. What Is SeaORM? 3. 2. Creating Schemas and Models 3. 2. 1. Defining Database Schema 3. 2. 2. Installing Dependencies 3. 2. 3. Migration 3. 3. SeaQuery 3. 3. 1. Query Builder 3. 3. 2. Identifiers and Iden 3. 3. 3. Database Connection 3. 3. 4. SELECT 3. 3. 5. INSERT 3. 3. 6. UPDATE 3. 3. 7. DELETE 3. 3. 8. Error Handling 3. 4. Connecting Users Table to HTTP Requests 3. 5. Database Connection 3. 5. 1. Connection Pool 3. 5. 2. Connection Options 3. 6. Modularization 3. 6. 1. Separating the DB Module 3. 6. 2. API Module Separation 3. 7. Completing Remaining Endpoints
Page
14
3. 7. 1. Category 3. 7. 2. Product 3. 7. 3. Routing 3. 8. Trying DBeaver 3. 9. Review Reference Chapter 4: Tower Middleware 4. 1. What Is Middleware? 4. 2. Adding Middleware Layers 4. 2. 1. Timeout Layer 4. 2. 2. Logging Layer 4. 2. 3. Compression Layer 4. 3. Example: Creating a JWT Authentication Layer 4. 4. Review Chapter 5: WebSocket 5. 1. Exploring WebSocket 5. 2. Using WebSocket 5. 3. Concurrent WebSocket Connections 5. 4. Authentication Headers 5. 5. Review Chapter 6: Project: Building a Chat Service 6. 1. Project Overview 6. 1. 1. What Is SSE? 6. 1. 2. Code Repository
Page
15
6. 2. Hands-on 6. 2. 1. Project Setup 6. 2. 2. Creating SSE Endpoints 6. 2. 3. Configuration Management and Database Connection 6. 2. 4. Creating REST API Endpoints 6. 2. 5. Building the Frontend 6. 2. 6. Automated Testing 6. 2. 7. Production Readiness and Deployment 6. 3. Review 6. 4. Closing Index
Page
16
About the Author Indo Yoon is a software engineer at SAP Labs Korea specializing in Python, Rust, and Go. A Seoul National University alumnus, he extends his impact beyond code as a frequent speaker and technical author. With a strong focus on web services, Indo is dedicated to advancing the developer community through his lectures and written works.
Page
17
About the Technical Reviewer Joshua Mo is a software engineer and technical writer specializing in Rust, AI infrastructure, and web development. He is currently the project lead for Rig, an open-source Rust framework for building agentic and AI- driven systems, where he focuses on system design, reliability, and developer ergonomics. Previously, Joshua worked at Shuttle, where he wrote many articles on using Axum, helped drive Rust adoption across companies, and supported developers learning async Rust and modern Rust web frameworks. He is known for translating real-world engineering experience into practical, production-focused guidance.
Page
18
(1) © The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2026 I. Yoon, Beginning Axum https://doi.org/10.1007/979-8-8688-2631-3_1 1. Rust and Server Development Indo Yoon1 Seoul, Korea (Republic of) Backend servers are the core of web applications. They connect frontends to databases, process and deliver data, and handle essential service operations like security, logging, and monitoring. Today, companies use many different programming languages and frameworks for backend development. What makes Rust stand out among them? Which companies are actually using Rust for their production backends? Learning Points Why Rust excels at backend development Real-world case studies of Rust backends in production Essential components for Rust server development 1.1 Why Rust? To understand why Rust excels at server development, we need to first examine what makes Rust itself so powerful. 1.1.1 Advantages of Rust Rust is a modern programming language that makes it easy to build fast, reliable programs. It delivers performance nearly identical to C/C++ (about 99%), but catches memory leaks and thread race conditions at compile time —problems that have plagued C/C++ developers for decades. This
Page
19
combination of high performance and high safety has made Rust the most desired language among developers for eight consecutive years in Stack Overflow’s global developer surveys [1]. Beyond performance and safety, Rust’s popularity stems from its excellent developer experience. As a modern language, it features elegant syntax and clear style guidelines that help you write correct code. Features like pattern matching and closures let you express complex logic concisely and efficiently. The compiler acts like a pair programmer—it not only identifies problems but also suggests solutions, helping you write the code you want faster. Rust also provides a convenient toolchain. A single toolchain called cargo handles everything from building and deploying to installing and updating dependencies. Additionally, rust-analyzer analyzes your source code in real time and provides immediate feedback as you write. It provides code completion, references to the code, type hints, and inline error messages in IDEs such as Visual Studio Code. Detailed instructions will be covered later. 1.1.2 Advantages of Developing Backends with Rust The advantage of developing backend servers with Rust is that you can easily build servers with both high performance and safety. For example, developing servers with JavaScript or Python often means hitting language- imposed performance limitations or spending significant time resolving thread race conditions and other concurrency issues. Even Java, widely used in Korea, can experience delays in server response times due to garbage collection pauses. In short, Rust is the ideal language for developing large-scale servers that require heavy CPU computation. 1.2 Rust Server Development Case Studies Leading tech companies like Microsoft, Cloudflare, Facebook, and Amazon are already actively adopting Rust for their backends. In Korea, companies like Kakao and Korbit have also adopted Rust as their backend language.
Page
20
Let’s examine some famous cases where companies used Rust to solve problems like concurrency limitations and performance degradation from garbage collection. 1.2.1 Figma Figma is a browser-based UI prototyping tool. Reflecting design shapes and functionality to users in real time is crucial. However, as the service grew, increased user load caused the existing TypeScript server’s CPU and memory usage to spike, leading to longer response times. To solve this, they decided to rewrite the server in Rust. The results were dramatic: compared to the TypeScript server, memory usage improved by up to 3.8x and response times improved by up to 16.4x [2]. 1.2.2 Discord Discord is a messenger service for text and video chat. As the service grew, they discovered periodic performance drops in their existing Go-based backend server. In the graph in Figure 1-1, the sections with periodic spikes represent the original server written in Go. You can see CPU usage spiking periodically, temporarily overloading the server and causing response times to increase cyclically. This was caused by Go’s garbage collector—while it periodically removes unused objects from memory, all other operations must pause. After rewriting the server in Rust, CPU usage stabilized and response times became much shorter.
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# Beginning Axum - Learning Modern Web Development With Rust
## 【One-Line Pitch】
A hands-on guide to building production-ready backend services with Axum, Rust's modern async web framework—perfect for developers who want to combine Rust's performance with practical web development skills, whether you're new to the language or an experienced engineer exploring new tools.
## 【Book Arc】
- **Opening (~0%–10%)**: Introduces why Rust matters for backend development through real-world case studies (Figma's 16.4x response time improvement, Discord's garbage collection issues), then walks through setting up the complete development environment including PostgreSQL, DBeaver, and Insomnia.
- **Early (~10%–23%)**: Covers Rust fundamentals essential for Axum—ownership, borrowing, references, modules, and structs—with practical examples and quizzes to cement understanding before diving into web development.
- **Early (~23%–32%)**: Builds the first Axum application with basic routing, then expands into request handling: query parameters, headers, form data, byte streams for large files, and multipart file uploads.
- **Middle (~32%–48%)**: Delves into advanced response patterns—status codes, typed headers, JSON responses—and introduces state management with Arc<Mutex> for shared mutable data across concurrent requests.
- **Middle (~48%+)**: Tackles real-world challenges like debugging complex handler errors with #[debug_handler], building proxy servers, and implementing caching strategies with shared state.
## 【Key Takeaways】
- **Rust's ownership model is the foundation** (Early): Every value has exactly one owner, and values are deallocated when their owner goes out of scope—this eliminates garbage collection pauses and makes performance predictable, which is why companies like Figma and Discord rewrote their backends in Rust.
- **Axum prioritizes developer experience** (Early): The framework provides consistent patterns like Extractors for input handling and intuitive routing macros, all built on Tokio—Rust's largest ecosystem project—ensuring long-term growth and support.
- **Query parameters need careful type handling** (Early): Using HashMap for query strings treats everything as strings, requiring manual conversion for numeric types; Axum's Query extractor supports typed structs for cleaner, safer parameter handling.
- **Byte streams handle large files efficiently** (Early): The Bytes type with Stream and AsyncRead traits lets you serve files like videos without loading them entirely into memory—critical for scalable media delivery.
- **Arc<Mutex> enables safe shared state** (Middle): Arc provides thread-safe reference counting for sharing values across threads, while Mutex ensures only one thread modifies data at a time—combining them creates shareable, modifiable state for concurrent handlers.
- **Tuple responses give fine-grained control** (Middle): Returning tuples like (StatusCode, Json<Value>) lets you precisely control HTTP status codes, headers, and body content—though nesting tuples can obscure types, so explicit typing is recommended.
- **Debugging handlers requires special tools** (Middle): When Axum's Handler trait errors seem cryptic, the #[debug_handler] attribute provides detailed diagnostics that reveal the actual issue in your handler code.
- **Caching with shared state is practical** (Middle): Using Arc<Mutex<HashMap>> as application state enables simple caching patterns—store responses by key, serve cached data for repeat requests, and update the cache for new ones.
## 【Reading Tips】
- **Skim the Rust fundamentals review** (~13%–23%) if you're already comfortable with ownership, borrowing, and modules—but don't skip it entirely, as the examples use these concepts heavily in later chapters.
- **Deep-read the request handling sections** (~29%–32%): Query parameters, headers, forms, and file uploads are the bread-and-butter of backend development, and these examples are directly applicable to real projects.
- **Pay special attention to the Arc<Mutex> explanation** (~39%–42%): This pattern appears throughout Axum applications for shared state, and understanding it well will save you hours of debugging concurrency issues.
- **Keep the development environment setup in mind** (~10%): PostgreSQL, DBeaver, and Insomnia are used throughout the book—setting them up correctly from the start prevents friction later.
- **Use the quiz questions** (~19%) as a self-check: They test whether you've absorbed the key concepts before moving to more complex material.
## 【Coverage Limits】
This guide covers the opening through middle sections of the book (approximately 0–48%), including Rust fundamentals, basic routing, request handling, and state management. The excerpts do not cover the database integration chapters (Chapter 3), middleware, WebSocket communication, or the final production deployment sections.
##
Passage locations
Page 20
ser-based UI prototyping tool. Reflecting design shapes and functionality to users in real time is crucial. However, as the service grew, increased user load...
View in text
Excerpt 2
g, which means a reference type to a string. When executing dummy in the main function, &x, which is a reference to variable x, was passed. This means tempor...
View in text
Excerpt 3
reads the file from disk has been omitted for convenience: use axum::{body::Body, response::IntoResponse}; use tokio_util::io::ReaderStream; async fn get_vid...
View in text
Excerpt 4
tedly finding and extracting needed fields, you can use the extract::FromRef trait to extract each field inside State declared as a struct. This makes code m...
View in text
Support Author
0.00
Total Amount (¥)
0
Donation Count
Please enter an amount
Minimum ¥1
You will be redirected to Alipay to complete payment, then return here.
Order created — please complete Alipay payment
{{#payUrl}} Pay with Alipay {{/payUrl}} {{^payUrl}}{{message}}
{{/payUrl}}
Donation failed:{{message}}
Log in to link the donation to your account (anonymous payment also works)
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later