Use the Rust programming language to build fully functional web applications with async Rust to amplify security and boost the performance of your programs Key FeaturesWork with cutting-edge web techniques such as distroless Rust servers, Terraform, and AWS deploymentGet acquainted with async conce
Rust Web Programming: A hands-on guide to developing, packaging, and deploying fully functional Rust web applications,
β Scribed by Maxwell Flitton
- Publisher
- Packt Publishing
- Year
- 2023
- Tongue
- English
- Leaves
- 666
- Edition
- 2
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Use the Rust programming language to build fully functional web applications with async Rust to amplify security and boost the performance of your programs
Key Features
- Work with cutting-edge web techniques such as distroless Rust servers, Terraform, and AWS deployment
- Get acquainted with async concepts such as actors and queuing tasks using lower-level frameworks like Tokio
- Build a full web application in Rust with a database, authentication, and frontend
Book Description
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.
What you will learn
- Structure and build scalable Rust web apps by creating a basic to-do list web app
- Manage authentication and databases in Rust web applications
- Get to grips with wrapping web applications in distroless
- Understand the building blocks of web development such as HTTPS, TCP, and middleware
- Build app infrastructure on AWS using Terraform with databases, servers, load balancers, HTTPS, and URL routing
- Build end-to-end tests using Postman
- Build async systems implementing the actor model using Tokio
Who this book is for
This Rust programming book is for web developers who want to learn and implement Rust to build web applications. Developers familiar with languages such as Python, Ruby, and JS will be able to use this book to build high performant web apps with Rust.
Although no prior experience in Rust is necessary, a solid understanding of web development principles, along with basic knowledge of HTML, CSS, and JavaScript, is necessary to get the most out of this book.
Table of Contents
- A Quick Introduction to Rust
- Designing Your Web Application in Rust
- Handling HTTP Requests
- Processing HTTP Requests
- Displaying Content in the Browser
- Data persistence with PostgreSQL
- Managing User Sessions
- Building RESTful Services
- Testing Our Application Endpoints and Components
- Deploying Our Application on AWS
- Configuring HTTPS with NGINX on AWS
- Recreating Our Application in Rocket
- Best Practices for a Clean Web App Repository
- Exploring the Tokio Framework
- Accepting TCP Traffic with Tokio
- Building Protocols on Top of TCP
- Implementing Actors and Async with the Hyper Framework
- Queuing Tasks with Redis
β¦ Table of Contents
Cover
Title Page
Copyright and Credits
Contributors
About the reviewers
Table of Contents
Preface
Part 1:Getting Started with Rust Web Development
Chapter 1: A Quick Introduction to Rust
Technical requirements
Why is Rust revolutionary?
Reviewing data types and variables in Rust
Using strings in Rust
Using integers and floats
Storing data in vectors and arrays
Mapping data with HashMaps
Handling results and errors
Controlling variable ownership
Copying variables
Moving variables
Immutable borrowing of variables
Mutable borrowing of variables
Scopes
Running through lifetimes
Building structs
Verifying with traits
Metaprogramming with macros
Summary
Questions
Answers
Further reading
Chapter 2: Designing Your Web Application in Rust
Technical requirements
Managing a software project with Cargo
Building with Cargo
Shipping crates with Cargo
Documenting with Cargo
Interacting with Cargo
Structuring code
Building to-do structs
Managing structs with factories
Defining functionality with traits
Interacting with the environment
Reading and writing JSON files
Revisiting traits
Processing traits and structs
Summary
Questions
Answers
Part 2:Processing Data and Managing Displays
Chapter 3: Handling HTTP Requests
Technical requirements
Introducing the Actix Web framework
Launching a basic Actix Web server
Understanding closures
Understanding asynchronous programming
Understanding async and await
Exploring async and await with web programming
Managing views using the Actix Web framework
Summary
Questions
Answers
Further reading
Chapter 4: Processing HTTP Requests
Technical requirements
Getting to know the initial setup for fusing code
Passing parameters into views
Using macros for JSON serializationΒ Β
Building our own serialization struct
Implementing the Serialize trait
Integrating serialization structs into our application code
Packaging our custom serialized struct to be returned to users
Extracting data from views
Extracting JSON from the body of a request
Extracting data from the header in requests
Simplifying header extraction with traits
Summary
Questions
Answers
Chapter 5: Displaying Content in the Browser
Technical requirements
Serving HTML, CSS, and JavaScript using Rust
Serving basic HTML
Reading basic HTML from files
Serving basic HTML loaded from files
Adding JavaScript to an HTML file
Communicating with our server using JavaScript
Injecting JavaScript into HTML
Adding the delete endpoint
Adding a JavaScript loading function
Adding JavaScript tags in the HTML
Building a rendering JavaScript function
Building an API call JavaScript function
Building JavaScript functions for buttons
Injecting CSS into HTML
Adding CSS tags to HTML
Creating a base CSS
Creating CSS for the home page
Serving CSS and JavaScript from Rust
Inheriting components
Creating a React app
Making API calls in React
Creating custom components in React
Creating our ToDoItem component
Creating custom components in React
Constructing and managing custom components in our App component
Lifting CSS into React
Converting our React application into a desktop application
Summary
Questions
Answers
Further reading
Part 3:Data Persistence
Chapter 6: Data Persistence with PostgreSQL
Technical requirements
Building our PostgreSQL database
Why we should use a proper database
Why use Docker?
How to use Docker to run a database
Running a database in Docker
Exploring routing and ports in Docker
Running Docker in the background with Bash scripts
Connecting to PostgreSQL with Diesel
Connecting our app to PostgreSQL
Creating our data models
Getting data from the database
Inserting into the database
Editing the database
Deleting data
Configuring our application
Building a database connection pool
Summary
Questions
Answers
Chapter 7: Managing User Sessions
Technical requirements
Creating our user model
Creating a User data module
Creating a NewUser data model
Altering the to-do item data model
Updating the schema file
Creating and running migration scripts on the database
Authenticating our users
Managing user sessions
Cleaning up authentication requirements
Configuring expiration of auth tokens
Adding authentication into our frontend
Summary
Questions
Answers
Further reading
Appendix
Chapter 8: Building RESTful Services
Technical requirements
What are RESTful services?
Mapping our layered system
Building a uniform interface
Implementing statelessness
Logging our server traffic
Caching
Code on demand
Summary
Questions
Answers
Part 4:Testing and Deployment
Chapter 9: Testing Our Application Endpoints and Components
Technical requirements
Building our unit tests
Building JWT unit tests
Building a configuration for tests
Defining the requirements for JWT tests
Building basic function tests for JWT
Building tests for web requests
Writing tests in Postman
Writing ordered requests for tests
Creating a test for an HTTP request
Automating Postman tests with Newman
Building an entire automated testing pipeline
Summary
Questions
Answers
Further reading
Chapter 10: Deploying Our Application on AWS
Technical requirements
Setting up our build environment
Setting up an AWS SSH key for an AWS EC2 instance
Setting up our AWS client
Setting up our Terraform build
Writing our Python application build script
Writing our Bash deployment script
Managing our software with Docker
Writing Docker image files
Building Docker images
Building an EC2 build server using Terraform
Orchestrating builds with Bash
Writing a Docker image file for the React frontend
Deploying images onto Docker Hub
Deploying our application on AWS
Running our application locally
Running our application on AWS
Writing our application build script
Summary
Further reading
Chapter 11: Configuring HTTPS with NGINX on AWS
Technical requirements
What is HTTPS?
Binary protocol
Compressed headers
Persistent connections
Multiplex streaming
Implementing HTTPS locally with docker-compose
Attaching a URL to our deployed application on AWS
Attaching an elastic IP to our server
Registering a domain name
Enforcing HTTPS on our application on AWS
Getting certificates for our URL
Creating multiple EC2 instances
Creating a load balancer for our traffic
Creating security groups to lock down and secure traffic
Updating our Python deployment script for multiple EC2 instances
Attaching our URL to the load balancer
Summary
Further reading
Questions
Answers
Part 5:Making Our Projects Flexible
Chapter 12: Recreating Our Application in Rocket
Technical requirements
What is Rocket?
Setting up our server
Plugging in our existing modules
Implementing Rocket traits
Plugging in our existing views
Accepting and returning JSON
Returning raw HTML
Returning status with JSON
Returning multiple statuses
Registering our views with Rocket
Plugging in our existing tests
Summary
Further reading
Questions
Answers
Chapter 13: Best Practices for a Clean Web App Repository
Technical requirements
The general layout of a clean repository
Getting our configuration from environment variables
Setting up a local development database
Managing variables in Postman tests
Building distroless tiny server Docker images
Building a clean test pipeline
Building continuous integration with GitHub Actions
Summary
Further reading
Questions
Answers
Part 6:Exploring Protocol Programming and Async Concepts with Low-Level Network Applications
Chapter 14: Exploring the Tokio Framework
Technical requirements
Exploring the Tokio framework for async programming
Working with workers
Exploring the actor model for async programming
Working with channels
Working with actors in Tokio
Summary
Further reading
Questions
Answers
Chapter 15: Accepting TCP Trafficwith Tokio
Technical requirements
Exploring TCP
Accepting TCP
Processing bytes
Passing TCP to an actor
Keeping track of orders with actors
Chaining communication between actors
Responding with TCP
Sending different commands via the client
Summary
Further reading
Questions
Answers
Chapter 16: Building Protocols onTop of TCP
Technical requirements
Setting up our TCP client and server
Setting up our TCP server
Setting up our TCP client
Processing bytes using structs
Creating a message sender client
Processing messages in the server
Utilizing framing
Rewriting our client so that it supports framing
Rewriting our server so that it supports framing
Building an HTTP frame on top of TCP
Summary
Further reading
Questions
Answers
Chapter 17: Implementing Actors and Async with the Hyper Framework
Technical requirements
Breaking down our project
Defining channel messages
Building our runner actor
Building our state actor
Handling HTTP requests using Hyper
Building an HTTP server using Hyper
Running our Hyper HTTP server
Summary
Further reading
Chapter 18: Queuing Tasks with Redis
Technical requirements
Breaking down our project
Building the HTTP server
Building the polling worker
Getting our application running with Redis
Defining tasks for workers
Defining messages for the Redis queue
Integrating routing in the HTTP server
Running it all in Docker
Summary
Further reading
Index
Other Books You May Enjoy
π SIMILAR VOLUMES
<p><span>Adopt the Rust programming language by learning how to build fully functional web applications and services and address challenges relating to safety and performance</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Build scalable web applications in Rust using popular framewo
<p><span>Adopt the Rust programming language by learning how to build fully functional web applications and services and address challenges relating to safety and performance</span></p><h4><span>Key Features</span></h4><ul><li><span><span>Build scalable web applications in Rust using popular framewo
<h4><span>Learn to Build Rust Programs, Test Applications and Create Your Own Cargo Packages in Rust</span></h4><span><br></span><p><span>Rust In Practice is an ultimate fast-paced guide for anyone looking to become a practitioner of the rust programming from day 1. This book covers everything from
<h4><span>Learn to Build Rust Programs, Test Applications and Create Your Own Cargo Packages in Rust</span></h4><span><br></span><p><span>Rust In Practice is an ultimate fast-paced guide for anyone looking to become a practitioner of the rust programming from day 1. This book covers everything from
Learn to Build Rust Programs, Test Applications and Create Your Own Cargo Packages with latest Rust 1.77 "Rust In Practice, Second Edition" is an updated book that builds on the previous edition's excellent foundation and is intended to help readers progress from novice to proficient Rust developers