Unlock Your Exclusive Benefits
local graph
Chapter 21 — Unlock Your Exclusive Benefits
Section titled “Chapter 21 — Unlock Your Exclusive Benefits”Step 3 After selecting your book, sign in to your Packt account or create one for free. Then upload your invoice (PDF, PNG, or JPG, up to 10 MB). Follow the on-screen instructions to finish the process.
Need Help If you get stuck and need help, visit https://www.packtpub.com/unlock-benefits/help for a detailed FAQ on how to find your invoices and more. This QR code will take you to the help page.
Note: If you are still facing issues, reach out to [email protected].
[blank page]
packt.com
Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry-leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Section titled “Why subscribe?”Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals Improve your learning with Skill Plans built especially for you Get a free eBook or video every month Fully searchable for easy access to vital information Copy and paste, print, and bookmark content
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. This document page is a collection of text extracted from various sources. The text is formatted in a clear, readable manner with proper spacing and formatting. The content is organized into distinct sections, each with its own heading and subheadings. The text is presented in a standard, clean font style, and there are no unnecessary decorative elements or images present. The document appears to be a formal document, possibly a report, study, or academic paper, with a focus on structured information and clear communication.
Other Books You May Enjoy
Section titled “Other Books You May Enjoy”If you enjoyed this book, you may be interested in these other books by Packt:
Learn React with TypeScript
Carl Rippon
ISBN: 9781836643173
- Apply React styling techniques to create stunning and visually engaging UIs
- Leverage server components to seamlessly integrate with client components for optimized performance
- Fetch and manage data efficiently in React for a smooth, responsive user experience
- Build interactive, validated forms with TypeScript and server actions to handle user input
- Share state efficiently across components using Zustand
- Structure scalable, multi-page applications effortlessly with Next.js
- Write unit tests for React apps with Vitest and React Testing Library Learn Model Context Protocol with Python Christoffer Noring ISBN: 9781806103232
- Understand the MCP protocol and its core components
- Build MCP servers that expose tools and resources to a variety of clients
- Test and debug servers using the interactive inspector tools
- Consume servers using Claude Desktop and Visual Studio Code Agents
- Secure MCP apps, as well as managing and mitigating common threats
- Build and deploy MCP apps using cloud-based strategies Other Books You May Enjoy
Packt is searching for authors like you
Section titled “Packt is searching for authors like you”If you’re interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Share your thoughts
Section titled “Share your thoughts”Now you’ve finished Rust Web Programming, Third Edition, we’d love to hear your thoughts! If you purchased the book from Amazon, please click here to go straight to the Amazon review page for this book and share your feedback or leave a review on the site that you purchased it from.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
[blank page]
Symbols
Section titled “Symbols”8-byte integers 10 16-byte integers 10, 11 .rs extension 64
Actix 430 Actix Web 120 actor 408 Amazon Machine Image (AMI) 493 Amazon Resource Name (ARN) 553 Amazon Web Services (AWS) 525 HTTPS, enforcing on application 545, 546 URL, attaching to deployed application 534, 535 American Standard Code for Information Interchange (ASCII) 526 API endpoints errors, handling 135, 136 application binary interface (ABI) 245, 579 application programming interface (API) 397 arrays 20 data, storing 12, 13 async sleep future building 107, 108 running 109, 110 async syntax with Rust 101-105 async task queue implementing 105 atomic end-to-end tests 453 building 461, 462 running 466-468 authentication, adding to frontend 326 login API call, building 326-328 login form component, building 328-330 login form, connecting to app 331, 332 tokens, adding to API calls 328 authentication server 337 auth server auth core module, building 300, 301 building 298, 299 data access layer, building 299, 300 interacting with 323-325 making accessible to other servers 340-344 networking layer, building 301-303 await syntax with Rust 101-105 AWS build environment AWS account, setting up 487-492 AWS SSH key, setting up for Amazon EC2 instance 484-487 setting up 484 Terraform build, setting up 492-496 Axum 134
backend API endpoints, connecting to frontend 194-198 API calls, building 206-208 API utils, defining 201-203 GET API call, defining 203 GET API call, integrating in main app 204, 205 interfaces, defining 199, 200 Index
| Bash | core layer |
|---|---|
| server-to-server communication, testing with 358-361 | |
| buffer overflow attack 3 | |
| BugSnag 400 | |
| C | crates |
| --- | --- |
| cache connection, to servers 382, 383 cache kernel, building 383-386 kernel, calling from auth server 390-394 kernel, calling from to-do server 386-390 caching benefits 364 Cargo 63, 72 basic compilation 64, 65 software project, managing with 64 used, for building basic application 65-67 used, for documentation 68-71 used, for interacting with Rust program 72-76 used, for shipping crates 67, 68 cargo run command 72 certificates obtaining, for URL 546-549 C interface 579 creating 581-583 client, queuing system building 625-627 compiler struct state, changing 59, 60 struct state, checking with 58 struct state, defining 58 compute unit, queuing system building 614-617 contract handler defining 50 contracts defining 50 handling, with functions 50 |
| --- | --- | | connecting, to server 124 file layout, defining 124, 125 networking layer, coding 126 | | create item HTTP kernel building 456-459 custom error building 137-140 mapping 140, 141 | | data mapping, with enums 15 mapping, with HashMaps 16, 18 storing, in arrays 12, 13 storing, in vectors 14 data access layer (DAL) 86 JSON file handle, building 87-89 module layout, defining 86, 87 SQLX, adding 268-272 storage API functions, building 89, 90 task, creating with 91-94 unit testing 442 used, for storing tasks 86 database connection pool 270 database migrations creating 285-287 database transactions connecting, to core layer 279-281 connecting, to server 281-284 defining 272-278 data extraction, from HTTP request headers 170 Actix header extraction trait, implementing 171-173 headers, extracting from request in Actix networking layer 173, 174 | header token modules, defining 170, 171 data, passing via POST body core create function, defining 153 core create function, in networking layer 154-157 create network route, configuring 157 endpoint, testing with cURL 158, 159 data, passing via POST requests 153 data storage cold storage 364 hot storage 364 warm storage 364 delete item HTTP kernel building 459-461 DELETE method using 159 delete workflow test creating 475-477 deployment script updating 559, 560 dereference operator 28 development environment building 178-182 connecting, to application 182 frontend server, running 183, 184 dictionaries 16 distributed denial-of-service (DDoS) attacks 550 DNS record 535 Docker advantages 258 database, running 261, 262 routing and ports, exploring 262-266 running, in background with Bash scripts 266, 267 system, deploying with 515 system, distributing with 512-515 system, packaging with 500 usage 259-261 Docker Compose HTTPS, implementing 528-530 Docker container 262 DockerFile 260 Docker Hub 259 Dockpack private repositories, managing 576-578 domain name registering 540-545 Domain Name System (DNS) 535 domain registrar 535 dynamic dispatch 101 E Elastic Compute Cloud (EC2) instances 525 prepping 549, 550 Elastic IP attaching, to server 536, 538, 540 Elasticsearch 408 end-to-end testing importance 451, 452 used, for testing workflows 468 writing 463-465 enums 20 data, mapping with 15, 16 errors, handling in API endpoints 19 custom error, building 137-140 custom error, mapping 140, 141 glue module, defining 136, 137 glue module, integrating into core layer 144-146 glue module, integrating into dal 141-144 glue module, integrating into networking layer 146 Index
| F | |
|---|---|
| factory 132 | |
| floats 9,12 | |
| foreign function interface (FFI) 582 | |
| frontend code | |
| refactoring 287-290 | |
| frontend, serving from Rust 186 | |
| embedded frontend, serving 189-194 | |
| embedding dependencies, defining 186-188 | |
| HTML file, embedding 188 | |
| React application, embedding 189 | |
| function export 234 | |
| futures 101 | |
| G | |
| garbage collection 3 | |
| generics | |
| enhancing, with traits 47 | |
| get all API | |
| defining 131-134 | |
| getters 43 | |
| glue module | |
| defining 136,137 | |
| integrating, into core layer 144-146 | |
| integrating, into dal 141-144 | |
| integrating, into networking layer 146 | |
| H | |
| hash function 307 | |
| hashing 307 | |
| HashMaps 14 | |
| data, mapping with 16-18 | |
| hosted zone 541 | |
| HTTP | |
| implementing, on top of TCP 595 | |
| HTTP/2 protocol, versus HTTP/1 protocol | |
| binary protocol 526 | |
| compressed headers 526 | |
| multiplex streaming 526 | |
| persistent connections 526 | |
| HTTP implementation, on top of TCP 595 | |
| basic server, defining 595,596 | |
| HTTP client, defining 596-598 | |
| HTTP protocol 597 | |
| HTTP request headers | |
| data, extracting from 170 | |
| HTTPS 526,528 | |
| implementing, on top of TCP 598-600 | |
| implementing, with Docker Compose 528-530 | |
| HTTP server implementation, in Hyper 113 | |
| environment, setting up 113 | |
| HTTP2, implementing for 116,117 | |
| main function, building for 114,115 | |
| request handle function, building 114 | |
| Hyper 134,197 | |
| Hypertext Transfer Protocol (HTTP) 484 | |
| I | |
| immutable borrowing 28 | |
| infrastructure as code (IaC) 492 | |
| integers 9 | |
| J | |
| Jaeger 408 | |
| JSON body | |
| defining 130 | |
| JSON file 257,258 | |
| considerations 86 | |
| JSON Web Token (JWT) 399 | |
| JSON Web Token (JWT) refactoring 312 | |
| decode function, creating to extract user credentials 316,317 | |
| Encode function, creating to encode user credentials 316 | |
| get key function, creating for encoding 315, 316 | |
| restructuring, for unique ID 313, 314 |
K kernel 244 kernel, queuing system building 614 Kubernetes 266
L load balancer creating, for traffic 550-554 URL, attaching to 560-563 logging 399, 400 logging, via database 408 actor 408, 409 actor, building 409-412 database, configuring 414-416 functions, updating 412-414 logging, via terminal 401 logger, defining 401-403 logger, integration into services 406-408 middleware, creating 403-405 login API building 317 core login API, creating 319 core login function, mounting to server 320-323 users, getting via email in data access layer 317-319
M macros calling, with trait 56, 57 messages, mapping with 49 used, for metaprogramming 46-49 using, in program 52, 54 man-in-the-middle attack 526
memory allocation 235 memory deallocation 235 memory reallocation 235 memory safety 3 metaprogramming with macros 46-48 microservices 568 microservices, benefits code isolation 574 flexibility to experiment 575 releases, rolling out 573, 574 microservices, pitfalls container orchestration 568-570 flying blind 570-572 network calls 572, 573 multi-factor authentication (MFA) 488 multiple React components rendering 213-217 mutable borrowing 28
N nanoservices 570 code, structuring through 77 directory 136 networking layer unit testing 430
O openssl package 531 operating system (OS) 260
P parameters passing, via URL 150-152 passwords storing 305-307 verifying 308, 309 Index
PATCH method used, for updating resources 167-169
PostgreSQL database 257 advantages 258 building 258
POST requests data, passing via 153
private repositories managing, with Dockpack 576-578
processes 98-101
PyO3 crate 584
Python Rust nanoservice, interfacing with 584, 585
Q queuing 608 applying 608-610
queuing system client 611 client, building 625-627 compute unit 612 compute unit, building 614-617 configurations 612, 613 kernel 612 kernel, building 614 layout, defining 611 running 627-629 server 612 server, building 623-625 worker 612 worker, building 617-622
R Rand reference link 68 Random-Access Memory (RAM) 234 React 179
React components create item form, building 209, 210 create item form, testing 212, 213 creating 208 form component, injecting into app 211 multiple React components, rendering 213-217
ReDB 591
Redis 365 advantages 365 setting up 365-367
Redis client building 378, 379 login/logout client, building 379-381 update client, building 381, 382
Redis module building 367, 368 login process, building 374, 375 logout process, building 375, 376 update process, building 376, 377 user session, defining 369-373
register contract macro building 51, 52
representational state transfer (REST) 397, 417
resolver 73
resources updating, with PATCH method 167-169
resources, deleting with DELETE method 159 delete function, adding to networking layer 161 delete JSON file method, defining 160 delete route, defining 162 JSON file code, refactoring 162-164
RESTful services 397, 398 features 398 frontend code, building on command 398, 399
results handling 18, 19 result type 20 Rocket 134, 196 Index
RocksDB 591 Rust 2,257 cheatsheet 5 data types, reviewing 5-7 innovative reason 3-5 variables 5-7 Rust Lib 579 Rust nanoservice interfacing, with Python 584,585 Rust playground URL 6
S salting 307 purposes 307 scopes 29 Second-Level Domain DNS (SLD DNS) 535 Second-Level-Domain (SLD) 534 security groups creating 554-559 server build pipeline building 497-500 server operations automating 164-167 server, queuing system building 623-625 server-side caching 364 server-to-server communication testing, with Bash 358-361 setter 43 Simple Storage Service (S3) bucket 499 SQLX adding, to data access layer 268-272 SSL installing 531-534 stack pointer adjustment 235 strings 20 using 7-9 string slice 8 structs building 33-38 managing, with API 82-85 styles insertion, with CSS 218 CSS, serving 218,219 page borders, defining for different screen sizes 220-222 React components, styling 222-226 system distributing, with Docker 512-515 system, deploying with Docker 515 deployment script, writing 520-522 Docker Compose system, writing for server 518-520 Terraform script, writing for server and database 516-518 system packaging, with Docker 500 base Docker image, building for servers 500-504 build config, building for microservices 508-512 build config, building for monolith 505-508
T task creating, with DAL 91-94 task-spawning function building 106,107 TCP client building 592-595 TCP server building 587-592 kernel, building for key-value messages 588,589 TCP client, building 592-595 Terraform build setting up 492-496 Terraform script 516 test runner bash script updating 478,479 threads 98-101 Time-To-Live (TTL) 535 to-do HTTP kernel building 453-456 to-do items get all API, defining 131,132 get_all, connecting to server 132-134 JSON body, defining 130 linking, to users in database 345-347 refactoring 127-129 serving 130 tethering 344 user IDs, adding to core functions 354,355 user IDs, adding to data access transactions 348-354 user IDs, adding to networking functions 355-357 to-do Rust library creating 580 to-do server 337 to-do structs, building 80-82 code, structuring through 77 file structure, configuring 78 task status, defining 79 Tokio 273 exploring 110-112 HTTP server, implementing in Hyper 113 Top-Level-Domain (TLD) 534 Top-Level Name DNS (TLN DNS) 535 traits functions, configuring with 54 implementing, for database handle 55,56 macro, calling with 56,57 signature, defining 54 used, for enhancing generics 47 verifying with 42-45 type state pattern 60 U unit test writing 424-426 unit testing 421 core testing 426-429 pitfalls 423 significance 421-423 unit testing, data access layer 442 DAL unit test, creating 443-446 teardown SQL command, defining 442,443 testing script, refactoring 446-448 unit testing, networking layer 430 database handle, mocking 432-434 mock service, defining 436 test module, defining 431 tests, writing 436-441 user cache handle, mocking 434,435 URL attaching, to load balancer 560-563 certificates, obtaining for 546-549 user creation 309 core create API endpoint, defining 310,311 create user database transactions, defining 309,310 networking create API endpoint, defining 311,312 user data model defining 303-305 users, obtaining from auth with unique ID 337 get by unique ID, adding to dal 338 get by unique ID, adding to networking 339,340 Index
V variable ownership controlling 21 lifetimes 30-32 scopes 29, 30 variables copying 22 immutable borrowing 25-27 moving 23, 24 mutable borrowing 28, 29 vectors 20 data, storing 14 virtual private cloud (VPC) ID 551 vtable 101
W wasm-client 244 WASM client building 249-253 WASM interface inspecting 237, 238 WASM kernel building 244, 245 wasm-lib 244 WASM library building 246-249 WASM module cheatsheet 235 defining 231-235 WebAssembly (WASM) 185, 229, 230, 611 build setup 231 loading, in frontend 236 loading, on local machine 243, 244 loading state, integrating into React component 239, 240 output, passing to subcomponents 240-243
web server code, writing 121-123 file layout, defining 120, 121 launching 120 running 123, 124 WebSockets 601-604, 629 worker, queuing system building 617-622 workflows 468 workflow, testing with end-to-end tests delete workflow test, creating 475-478 existing code, configuring 469, 470 kernel API call, building 472-474 kernel API call, building for user creation 470-472 test runner bash script, updating 478, 479 test workspace, creating 474, 475
Y YAML code 260
Z zone file 535
[blank page]