Deliver fast, reliable, and maintainable applications by building backend servers, services, and frontends all in nothing but Rust.
In Rust Servers, Services, and Apps, you’ll learn:
• Developing database-backed web services in Rust
• Building and securing RESTful APIs
• Writing server-side web applications in Rust
• Measuring and benchmarking web service performance
• Packaging and deploying web services
• Full-stack Rust applications
The blazingly fast, safe, and efficient Rust language has been voted “most loved” for multiple consecutive years on the StackOverflow survey. Rust Server, Services, and Apps shows you why! Inside, you’ll build web servers, RESTful services, server-rendered apps, and client frontends just using Rust. You’ll learn to write code with small and predictable resource footprints, and build high-performing applications with unmatched safety and reliability.
About the technology
Build speedy, stable, and safe web servers in Rust! With a unique approach to memory management and concurrency, Rust excels at getting the low-level details right so your applications run fast and flawlessly. And Rust’s incredible compiler helps you avoid expensive mistakes when you’re deploying web services and other core components in production.
About the book
Rust Servers, Services, and Apps shows you how to create modern distributed web apps using the Rust language. You’ll start with the basics: building a simple HTTP server and a RESTful web service. Then, you’ll make them production ready by adding security, database interactivity, and error handling. Finally, you’ll tackle a digital storefront service, create a single page app, and dig into asynchronous programming. All examples are fully illustrated and include annotated code you can easily adapt to your own projects.
What's inside
• Craft resilient and secure RESTful APIs
• Package and deploy web services
• Refactor fearlessly thanks to Rust’s guaranteed safety
• Slash costs with Rust’s runtime and compile-time optimizations
• Asynchronous programming with Rust
About the reader
For web developers who know the basics of Rust.
About the author
Prabhu Eshwarla is the CTO of a startup building a layer-1 blockchain using Rust. Previously, he held engineering and leadership roles at Hewlett Packard.
Author(s): Prabhu Eshwarla
Edition: 1
Publisher: Manning
Year: 2023
Language: English
Commentary: Publisher's PDF
Pages: 328
City: Shelter Island, NY
Tags: Web Applications; Asynchronous Programming; HTTP; Docker; Refactoring; Unit Testing; Web Servers; Rust; Error Handling; TCP/IP; Back-End Development; Database Programming; RESTful API
Rust Servers, Services, and Apps
brief contents
contents
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
Symbols
Numerics
A
B
C
D
E
F
G
H
I
K
L
M
N
O
P
Q
R
S
T
U
V
W
Rust Servers, Services, and Apps - back