Rust Servers, Services, and Apps

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Rust Servers, Services, and Apps is a hands-on guide to developing modern distributed web applications with Rust. You’ll learn how to build efficient services, write custom web servers, and even build full stack applications end-to-end in Rust. You’ll start with the foundations, using Rust to build an HTTP server, and RESTful API that you’ll secure, debug, and evolve with fearless refactoring. You’ll then put Rust through its paces to develop a digital storefront service, and a single-page client-side application. This fastpaced book is packed with code samples you can adapt to your own projects, and detailed annotations to help you understand how Rust works under the hood. About the technology The blazingly fast, safe, and efficient Rust language has been voted “most loved” for five consecutive years on the StackOverflow survey. It’s easy to see why. Rust combines all the features of a modern language with the low-latency power of C. Its efficiency will slash your runtime footprint―and your cloud hosting bills―and its flexibility lets you write network programs and high-level applications with equal ease.

Author(s): Prabhu Eshwarla
Publisher: Manning Publications Co.
Year: 2023

Language: English
Pages: 318

inside front cover
Rust Servers, Services, and Apps
Copyright
contents
front matter
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A road map
About the code
liveBook discussion forum
Other online resources
about the author
about the cover illustration
Part 1. Web servers and services
1 Why Rust for web applications?
1.1 Introducing modern web applications
1.2 Choosing Rust for web applications
1.2.1 Characteristics of web applications
1.2.2 Benefits of Rust for web applications
1.2.3 What does Rust not have?
1.3 Visualizing the example application
1.3.1 What will we build?
1.3.2 Technical guidelines for the example application
Summary
2 Writing a basic web server from scratch
2.1 The networking model
2.2 Writing a TCP server in Rust
2.2.1 Designing the TCP/IP communication flow
2.2.2 Writing the TCP server and client
2.3 Writing an HTTP server in Rust
2.3.1 Parsing HTTP request messages
2.3.2 Constructing HTTP response messages
2.3.3 Writing the main() function and server module
2.3.4 Writing the router and handler modules
2.3.5 Testing the web server
Summary
3 Building a RESTful web service
3.1 Getting started with Actix
3.1.1 Writing the first REST API
3.1.2 Understanding Actix concepts
3.2 Building web APIs with REST
3.2.1 Defining the project scope and structure
3.2.2 Defining and managing application state
3.2.3 Defining the data model
3.2.4 Posting a course
3.2.5 Getting all the courses for a tutor
3.2.6 Getting the details of a single course
Summary
4 Performing database operations
4.1 Setting up the project structure
4.2 Writing our first async connection to database (iteration 1)
4.2.1 Selecting the database and connection library
4.2.2 Setting up the database and connecting with an async pool
4.3 Setting up the web service and writing unit tests (iteration 2)
4.3.1 Setting up the dependencies and routes
4.3.2 Setting up the application state and data model
4.3.3 Setting up the connection pool using dependency injection
4.3.4 Writing the unit tests
4.4 Creating and querying records from the database (iteration 3)
4.4.1 Writing database access functions
4.4.2 Writing handler functions
4.4.3 Writing the main() function for the database-backed web service
Summary
5 Handling errors
5.1 Setting up the project structure
5.2 Basic error handling in Rust and Actix Web
5.3 Defining a custom error handler
5.4 Error handling for retrieving all courses
5.5 Error handling for retrieving course details
5.6 Error handling for posting a new course
Summary
6 Evolving the APIs and fearless refactoring
6.1 Revamping the project structure
6.2 Enhancing the data model for course creation and management
6.2.1 Making changes to the data model
6.2.2 Making changes to the course APIs
6.3 Enabling tutor registration and management
6.3.1 Data model and routes for tutors
6.3.2 Handler functions for tutor routes
6.3.3 Database access functions for tutor routes
6.3.4 Database scripts for tutors
6.3.5 Run and test the tutor APIs
Summary
Part 2. Server-side web applications
7 Introducing server-side web apps in Rust
7.1 Introducing server-side rendering
7.2 Serving a static web page with Actix
7.3 Rendering a dynamic web page with Actix and Tera
7.4 Adding user input with forms
7.5 Displaying a list with templates
7.6 Writing and running client-side tests
7.7 Connecting to the backend web service
Summary
8 Working with templates for tutor registration
8.1 Writing the initial web application
8.2 Displaying the registration form
8.3 Handling registration submission
Summary
9 Working with forms for course maintenance
9.1 Designing user authentication
9.2 Setting up the project structure
9.3 Implementing user authentication
9.4 Routing HTTP requests
9.5 Creating a resource with the HTTP POST method
9.6 Updating a resource with the HTTP PUT method
9.7 Deleting a resource with the HTTP DELETE method
Summary
Part 3. Advanced topic: Async Rust
10 Understanding async Rust
10.1 Introducing async programming concepts
10.2 Writing concurrent programs
10.3 Diving deeper into async Rust
10.4 Understanding futures
10.5 Implementing a custom future
Summary
11 Building a P2P node with async Rust
11.1 Introducing peer-to-peer networks
11.1.1 Transport
11.1.2 Peer identity
11.1.3 Security
11.1.4 Peer routing
11.1.5 Messaging
11.1.6 Stream multiplexing
11.2 Understanding the core architecture of libp2p networking
11.2.1 Peer IDs and key pairs
11.2.2 Multiaddresses
11.2.3 Swarm and network behavior
11.3 Exchanging ping commands between peer nodes
11.4 Discovering peers
Summary
12 Deploying web services with Docker
12.1 Introducing production deployment of servers and apps
12.1.1 Software deployment cycle
12.1.2 Docker container basics
12.2 Writing the Docker container
12.2.1 Checking the Docker installation
12.2.2 Writing a simple Docker container
12.2.3 Multistage Docker build
12.3 Building the database container
12.3.1 Packaging the Postgres database
12.3.2 Creating database tables
12.4 Packaging the web service with Docker
12.5 Orchestrating Docker containers with Docker Compose
Summary
Appendix. Postgres installation
index
inside back cover