Rust Web Programming (eBook)

A hands-on guide to developing, packaging, and deploying fully functional Rust web applications

(Autor)

eBook Download: EPUB
2023
666 Seiten
Packt Publishing (Verlag)
978-1-80323-665-0 (ISBN)

Lese- und Medienproben

Rust Web Programming - Maxwell Flitton
Systemvoraussetzungen
35,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

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.


Use the Rust programming language to build fully functional web applications with async Rust to amplify security and boost the performance of your programsKey FeaturesWork with cutting-edge web techniques such as distroless Rust servers, Terraform, and AWS deploymentGet acquainted with async concepts such as actors and queuing tasks using lower-level frameworks like TokioBuild a full web application in Rust with a database, authentication, and frontendBook DescriptionAre 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 learnStructure and build scalable Rust web apps by creating a basic to-do list web appManage authentication and databases in Rust web applicationsGet to grips with wrapping web applications in distrolessUnderstand the building blocks of web development such as HTTPS, TCP, and middlewareBuild app infrastructure on AWS using Terraform with databases, servers, load balancers, HTTPS, and URL routingBuild end-to-end tests using PostmanBuild async systems implementing the actor model using TokioWho this book is forThis 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.]]>

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.

Who this book is for


This book on web programming with Rust is for web developers who have programmed in traditional languages, such as Python, Ruby, JavaScript, and Java, and are looking to develop high-performance web applications with Rust. Although no prior experience with Rust is necessary, a solid understanding of web development principles and basic knowledge of HTML, CSS, and JavaScript is required if you want to get the most out of this book.

What this book covers


Chapter 1, A Quick Introduction to Rust, provides the basics of the Rust programming language.

Chapter 2, Designing Your Web Application in Rust, covers building and managing applications in Rust.

Chapter 3, Handling HTTP Requests, covers building a basic Rust server that handles HTTP requests using the Actix Web framework.

Chapter 4, Processing HTTP Requests, covers extracting and handling data from an incoming HTTP request.

Chapter 5, Displaying Content in the Browser, covers displaying data from the server and sending requests to the server from the browser with HTML, CSS, and JavaScript with React.

Chapter 6, Data Persistence with PostgreSQL, covers managing and structuring data in PostgreSQL and interacting with the database with our Rust web server.

Chapter 7, Managing User Sessions, covers authentication and managing of user sessions when making requests to the web server.

Chapter 8, Building RESTful Services, covers implementing RESTful concepts for Rust web servers.

Chapter 9, Testing Our Application Endpoints and Components, covers end-to-end testing pipelines and unit testing on Rust web servers using Postman.

Chapter 10, Deploying Our Application on AWS, covers building automated build and deployment pipelines to deploy on AWS using Docker and automating the infrastructure building with Terraform.

Chapter 11, Configuring HTTPS with NGINX on AWS, covers configuring HTTPS and routing to servers via load balancing on AWS with NGINX and routing traffic to different applications depending on endpoints in the URL.

Chapter 12, Recreating Our Application in Rocket, covers slotting our existing application into a Rocket web framework.

Chapter 13, Best Practices for a Clean Web App Repository, covers cleaning up a web application repository with multi-stage Docker builds for smaller images and init Docker containers to automate database migrations on deployment.

Chapter 14, Exploring the Tokio Framework, covers implementing basic async code using the Tokio framework to facilitate an async runtime.

Chapter 15, Accepting TCP Traffic with Tokio, covers sending, receiving, and processing TCP traffic.

Chapter 16, Building Protocols on Top of TCP, covers processing TCP byte streams into advanced data structures using structs and framing.

Chapter 17, Implementing Actors and Async with the Hyper Framework, covers building an async system using the actor framework that accepts HTTP requests via the Hyper framework.

Chapter 18, Queuing Tasks with Redis, covers accepting HTTP requests and packaging them as tasks to put on a Redis queue for a pool of workers to process.

To get the most out of this book


You will need to know some basic concepts around HTML and CSS. You will also need to have some basic understanding of JavaScript. However, the HTML, CSS, and JavaScript is only needed for displaying data in the browser. If you are just reading the book to build backend API servers in Rust, then knowledge of HTML, CSS, and JavaScript is not needed.

Some basic understanding of programming concepts such as functions and loops will also be needed as these will not be covered in the book.

Software/hardware covered in the book

Operating system requirements

Rust

Windows, macOS, or Linux (any)

Node (for JavaScript)

Windows, macOS, or Linux (any)

Python 3

Windows, macOS, or Linux (any)

Docker

Windows, macOS, or Linux (any)

docker-compose

Windows, macOS, or Linux (any)

Postman

Windows, macOS, or Linux (any)

Terraform

Windows, macOS, or Linux (any)

To take full advantage of the deployment on AWS chapters, you will need an AWS account, which might cost if you are not eligible for the Free Tier. However, the builds are automated with Terraform, so spinning up builds and tearing them down will be quick and easy, so you will not need to keep the infrastructure running while working through the book, keeping the costs to a minimum.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

By the of this book, you will have a solid foundation of building and deploying Rust servers. However, it must be noted that Rust is a powerful language. As this book focuses on web programming and deployment, there is scope for improvement in Rust programming after the book. Further reading on Rust is advised after the book to enable you to solve more complex problems.

Download the example code files


You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Rust-Web-Programming-2nd-Edition....

Erscheint lt. Verlag 27.1.2023
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Web / Internet
Informatik Weitere Themen Hardware
ISBN-10 1-80323-665-5 / 1803236655
ISBN-13 978-1-80323-665-0 / 9781803236650
Haben Sie eine Frage zum Produkt?
EPUBEPUB (Ohne DRM)

Digital Rights Management: ohne DRM
Dieses eBook enthält kein DRM oder Kopier­schutz. Eine Weiter­gabe an Dritte ist jedoch rechtlich nicht zulässig, weil Sie beim Kauf nur die Rechte an der persön­lichen Nutzung erwerben.

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür die kostenlose Software Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich