Leanpub Header

Skip to main content

Modern Web Development with Rust and Axum

Building Production-Grade APIs and Services

Modern Web Development with Rust and Axum
This book is 100% completeLast updated on 2026-10-12
+5,752 words in the last 30 days

Build production-ready web services with Rust and Axum. Follow Taskflow, a practical task management API, from the basics through authentication, databases, real-time features, observability and deployment. With code examples, you’ll learn how the pieces fit together and gain the skills to build reliable Rust APIs.

Minimum price

$25.00

$35.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
293
Pages
About

About

About the Book

This book shows you how to design, build, test, deploy and operate production-ready web applications with Rust and the Axum framework. Using a task management API called Taskflow as a running example, you’ll start with the fundamentals and gradually work your way into more advanced topics such as authentication, database integration, real-time communication, observability and containerized deployment. The examples are explained in context so you can follow along and understand how each part fits into the application. The book assumes you have some basic knowledge of Rust syntax, while introducing the web development and async concepts you need along the way. It targets Axum 0.8.x, Tokio 1.x and Rust edition 2021.

Author

About the Author

Steve Publications

Steve is a technology professional with over 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. He specializes in analyzing complex systems, identifying weaknesses and improving security.

Beyond his professional work, Steve collaborates with researchers and industry experts to create practical technical books covering software development, cybersecurity, cloud computing, DevOps, AI and enterprise technologies. His goal is to help IT professionals, students and enthusiasts develop practical skills through clear explanations, real-world examples and hands-on exercises.

At Steve Publications, we use AI to assist with translation, proofreading and editing but not to replace the research, technical expertise or hands-on experience behind our books. Some authors publish under pseudonyms for privacy or professional reasons.

Every book is written, reviewed and maintained by experienced professionals, supported by a private community of over 420 engineers and researchers. We prioritize technical accuracy, practical value and regularly updated content over mass-produced AI-generated text.

We welcome experienced professionals interested in writing or reviewing books, especially in specialized and emerging technology fields. If you'd like to contribute, contact us with your area of expertise.

We stand behind our work. If a book doesn't meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

Building Production-Grade APIs and Services

Introduction

  1. What You Will Learn
  2. The Running Example: Taskflow API
  3. How This Book Is Structured
  4. Prerequisites and Versions
  5. How to Read This Book

Chapter 1: Why Rust for Web Development

  1. The Case for Rust in Web Services
  2. Landscape of Rust Web Frameworks
  3. Why Axum Stands Out
  4. Introducing Our Running Example: A Task Management API
  5. How to Read This Book
  6. Summary

Chapter 2: Project Setup and Architecture

  1. Rust Toolchain and Edition Selection
  2. Cargo Configuration and Dependency Management
  3. Directory Layout for Scalable Projects
  4. Our First Axum Server: Hello World with Structure
  5. Environment Configuration Strategy
  6. Summary

Chapter 3: Tokio and Asynchronous Rust

  1. How async/await Works in Rust
  2. The Tokio Runtime: Multithreaded vs Current Thread
  3. Tasks, Spawning and Joining
  4. Channels and Concurrent Communication
  5. Timeouts, Sleeps and Scheduling Control
  6. Summary

Chapter 4: Tower, Hyper and Axum’s Architecture

  1. The Tower Service Trait: Composable Asynchronous Services
  2. Middleware as Service Layers
  3. Hyper: The Low-Level HTTP Engine
  4. How Axum Fits Into the Stack
  5. Understanding the Type-Driven Design Philosophy
  6. Summary

Chapter 5: Routing and Extractors

  1. Defining Routes with the Router Combinator
  2. Path Parameters and Their Types
  3. Query Parameters and Structured Extraction
  4. Application State and the State Extractor
  5. Nested Routers and Modular Route Organization
  6. Summary

Chapter 6: Request and Response Handling

  1. Response Types and Status Codes
  2. JSON Serialization with serde_json
  3. Form Data and URL-Encoded Bodies
  4. Headers: Reading and Writing
  5. Cookies and Session Identifiers
  6. Content Negotiation Patterns
  7. Summary

Chapter 7: Error Handling and Validation

  1. Designing Application Error Types
  2. The IntoResponse Trait for Error Conversion
  3. Centralized Error Handlers
  4. Input Validation with Validator Crates
  5. Separating Internal Errors from Client-Facing Messages
  6. Summary

Chapter 8: Authentication and Authorization

  1. Password Hashing with Argon2
  2. Session-Based Authentication
  3. JWT Authentication Flow
  4. Extractors for Authenticated Requests
  5. Role-Based Authorization Patterns
  6. Summary

Chapter 9: Web Security Practices

  1. Cross-Origin Resource Sharing (CORS) Configuration
  2. Security Headers and Helmet-Like Middleware
  3. CSRF Protection Strategies
  4. Rate Limiting and Abuse Prevention
  5. Secure Configuration and Secrets Management
  6. Summary

Chapter 10: Database Integration with SQLx

  1. Choosing a Database Driver
  2. Connection Pooling with SQLx Pools
  3. Running Queries and Mapping Results
  4. Database Migrations with sqlx-migrate
  5. Transactions and Atomic Operations
  6. Summary

Chapter 11: Repository and Service Patterns

  1. The Repository Pattern in Rust
  2. Service Layer Design
  3. Dependency Injection Through Application State
  4. Domain Modeling and Type Safety
  5. Structuring Large Applications
  6. Summary

Chapter 12: Real-Time Communication with WebSockets

  1. WebSocket Upgrade Flow
  2. Handling Bidirectional Messages
  3. Connection State and Broadcast Patterns
  4. Scaling WebSocket Applications
  5. Server-Sent Events as an Alternative
  6. Summary

Chapter 13: File Handling and Static Assets

  1. Serving Static Files Efficiently
  2. File Uploads with Multipart Forms
  3. Streaming Large Responses
  4. File Validation and Security Considerations
  5. Summary

Chapter 14: RESTful API Design and Documentation

  1. REST Principles in Practice
  2. Pagination, Filtering and Sorting Patterns
  3. API Versioning Strategies
  4. Generating OpenAPI/Swagger Documentation
  5. Request/Response Schema Design
  6. Summary

Chapter 15: Testing Strategies

  1. Unit Testing Handlers and Services
  2. Integration Testing with axum_test or reqwest
  3. Database Testing Strategies
  4. Mocking External Dependencies
  5. Test Organization for Large Projects
  6. Summary

Chapter 16: Observability and Performance

  1. Structured Logging with Tracing
  2. Distributed Tracing in Microservices
  3. Metrics Collection and Export
  4. Profiling and Identifying Bottlenecks
  5. Caching Strategies: In-Memory and Distributed
  6. Summary

Chapter 17: Deployment and Operations

  1. Building Optimized Docker Images
  2. Reverse Proxies: Nginx and Caddy
  3. TLS Termination and Certificate Management
  4. Graceful Shutdown and Health Checks
  5. CI/CD Pipelines for Rust Services
  6. Production Monitoring and Alerting
  7. Summary

Conclusion: The Path Forward

  1. What Makes This Stack Special
  2. Key Principles to Remember
  3. Where to Go From Here
  4. Continuing Your Rust Journey
  5. Final Thoughts

References

  1. Official Documentation
  2. Axum Repository and Examples
  3. Axum Announcements and Blog Posts
  4. Rust Web Framework Comparisons
  5. Authentication and Security
  6. Database and SQLx
  7. Testing
  8. OpenAPI and Documentation
  9. Observability
  10. Deployment and Docker
  11. Tokio Runtime
  12. Additional Resources
  13. Community and Learning

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub