Book Image

Rust Web Programming - Second Edition

By : Maxwell Flitton
Book Image

Rust Web Programming - Second Edition

By: Maxwell Flitton

Overview of this book

Are safety and high performance a big concern for you while developing web applications? With this practical Rust book, you’ll discover how you can implement Rust on the web to achieve the desired performance and security as you learn techniques and tooling to build fully operational web apps. In this second edition, you’ll get hands-on with implementing emerging Rust web frameworks, including Actix, Rocket, and Hyper. It also features HTTPS configuration on AWS when deploying a web application and introduces you to Terraform for automating the building of web infrastructure on AWS. What’s more, this edition also covers advanced async topics. Built on the Tokio async runtime, this explores TCP and framing, implementing async systems with the actor framework, and queuing tasks on Redis to be consumed by a number of worker nodes. Finally, you’ll go over best practices for packaging Rust servers in distroless Rust Docker images with database drivers, so your servers are a total size of 50Mb each. By the end of this book, you’ll have confidence in your skills to build robust, functional, and scalable web applications from scratch.
Table of Contents (27 chapters)
Free Chapter
1
Part 1:Getting Started with Rust Web Development
4
Part 2:Processing Data and Managing Displays
8
Part 3:Data Persistence
12
Part 4:Testing and Deployment
16
Part 5:Making Our Projects Flexible
19
Part 6:Exploring Protocol Programming and Async Concepts with Low-Level Network Applications

Preface

Do you want to push your web applications to the limit for speed and low energy consumption but still have memory safety? Rust enables you to have memory safety without the garbage collection and a similar energy consumption as the C programming language. This means you can create high-performance and secure applications with relative ease.

This book will take you through each stage of web development resulting in you deploying advanced web applications built in Rust and packaged in distroless Docker, resulting in server images around the size of 50 MB on AWS using automated build and deployment pipes that we created.

You’ll start with an introduction to programming in Rust so you can avoid the common pitfalls when migrating from a traditional dynamic programming language. The book will show you how to structure Rust code for a project that spans multiple pages and modules. Next, you’ll explore the Actix Web framework and get a basic web server up and running. As you advance, you’ll learn how to process JSON requests and display the data from the server via HTML, CSS, and JavaScript and even build a basic React application for our data. You’ll also learn how to persist data and create RESTful services in Rust, where we log in and authenticate users and cache data in the frontend. Later, you’ll build an automated build and deployment process for the app on AWS over two EC2 instances, where we load balance the HTTPS traffic from a registered domain to our application on those EC2 instances, which we will build using Terraform. You will also lock down the traffic directly to the EC2 instances by configuring security groups in Terraform. You’ll then cover multi-layered builds to produce distroless Rust images. Finally, you’ll cover advanced web concepts exploring async Rust, Tokio, Hyper, and TCP framing. With these tools, you will implement the actor model to enable you to implement advanced complex async real-time event processing systems, practicing by building a basic stock purchasing system. You’ll finish the book by building your own queuing mechanism on Redis, where your own Rust home-built server and worker nodes consume the tasks on the queue and process these tasks.