Rust Web Development
- Length: 400 pages
- Edition: 1
- Language: English
- Publisher: Manning
- Publication Date: 2023-01-24
- ISBN-10: 1617299006
- ISBN-13: 9781617299001
- Sales Rank: #200401 (See Top 100 Books)
Create bulletproof, high-performance web apps and servers with Rust.
In Rust Web Development, you’ll learn to build server-side web applications using the Rust language and its key libraries. If you know the basics of Rust, you’ll quickly pick up some pro tips for setting up your projects and organizing your code.
Rust Web Development gets you hands-on fast, with numerous small and large examples. You’ll get up to speed with how Rust streamlines backend development, implements authentication flows, and even makes it easier for your APIs to interact. As you go, you’ll build a complete Q&A web service and iterate on your code chapter-by-chapter, just like a real development project.
Rust Web Development 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 about the author about the cover illustration Part 1—Introduction to Rust 1 Why Rust? 1.1 Batteries included: Rust’s tooling 1.2 The Rust compiler 1.3 Rust for web services 1.4 Maintainability of Rust applications Summary 2 Laying the foundation 2.1 Following the Rust playbook 2.1.1 Modeling your resources with structs 2.1.2 Understanding options 2.1.3 Using documentation to solve errors 2.1.4 Handling strings in Rust 2.1.5 Taking an excursion into moving, borrowing, and ownership 2.1.6 Using and implementing traits 2.1.7 Handling results 2.2 Creating our web server 2.2.1 Handling multiple requests at once 2.2.2 Rust’s asynchronous environment 2.2.3 Rust’s handling of async/await 2.2.4 Using Rust’s Future type 2.2.5 Choosing a runtime 2.2.6 Choosing a web framework Summary Part 2—Getting started 3 Create your first route handler 3.1 Getting to know our web framework: Warp 3.1.1 What is included in Warp 3.1.2 Warp’s filter system 3.2 GET your first JSON response 3.2.1 Align with your framework’s way of thinking 3.2.2 Handle the success route 3.2.3 Get help from Serde 3.2.4 Handle errors gracefully 3.3 Handling CORS headers 3.3.1 Returning CORS headers on the application level 3.3.2 Testing CORS responses Summary 4 Implement a RESTful API 4.1 GET questions from in-memory 4.1.1 Setting up a mock database 4.1.2 Preparing a set of test data 4.1.3 Reading from the fake database 4.1.4 Parsing query parameters 4.1.5 Returning custom errors 4.2 POST, PUT, and DELETE questions 4.2.1 Updating our data in a thread-safe way 4.2.2 Adding a question 4.2.3 Updating a question 4.2.4 Handling malformed requests 4.2.5 Removing questions from the storage 4.3 POST answers via url-form-encoded 4.3.1 Difference between url-form-encoded and JSON 4.3.2 Adding answers via url-form-encoded Summary 5 Clean up your codebase 5.1 Modularizing your code 5.1.1 Using Rust’s built-in mod system 5.1.2 Practical folder structure for different use cases 5.1.3 Creating libraries and sub-crates 5.2 Documenting your code 5.2.1 Using doc comments and private comments 5.2.2 Adding code in your comments 5.3 Linting and formatting your codebase 5.3.1 Installing and using Clippy 5.3.2 Formatting your code with Rustfmt Summary 6 Logging, tracing, and debugging 6.1 Logging in your Rust application 6.1.1 Implementing logging in your web service 6.1.2 Logging incoming HTTP requests 6.1.3 Creating structured logs 6.2 Tracing in asynchronous applications 6.2.1 Introducing the Tracing crate 6.2.2 Integrating tracing in our application 6.3 Debugging Rust applications 6.3.1 Using GDB on the command line 6.3.2 Debugging our web service with LLDB 6.3.3 Using Visual Studio Code and LLDB Summary 7 Add a database to your application 7.1 Setting up our example database 7.2 Creating our first tables 7.3 Working with a database crate 7.3.1 Adding SQLx into our project 7.3.2 Connecting Store to our database 7.4 Reimplementing our route handlers 7.4.1 Adding the database to get_questions 7.4.2 Reimplementing the add_question route handler 7.4.3 Adjusting the update and delete questions handler 7.4.4 Updating the add_answer route 7.5 Error handling and tracing database interactions 7.6 Integrating SQL migrations 7.7 Case study: Switching database management systems Summary 8 Integrate third-party APIs 8.1 Preparing the codebase 8.1.1 Picking an API 8.1.2 Getting to know our HTTP crate 8.1.3 Adding an example HTTP call with Reqwest 8.1.4 Handling errors for external API requests 8.2 Deserializing JSON responses to structs 8.2.1 Gathering API response information 8.2.2 Creating types for our API responses 8.3 Sending questions and answers to the API 8.3.1 Refactoring the add_question route handler 8.3.2 Making profanity checks for updating questions 8.3.3 Updating the add_answer route handler 8.4 Handling timeouts and multiple requests at once 8.4.1 Implementing a retry for external HTTP calls 8.4.2 Executing futures concurrently or in parallel Summary Part 3—Bring it into production 9 Add authentication and authorization 9.1 Adding authentication to our web service 9.1.1 Creating the user concept 9.1.2 Migrating the database 9.1.3 Adding the registration endpoint 9.1.4 Hashing the password 9.1.5 Handling duplicate account errors 9.1.6 Stateful vs. stateless authentication 9.1.7 Adding the login endpoint 9.1.8 Adding an expiry date to tokens 9.2 Adding authorization middleware 9.2.1 Migrating the database tables 9.2.2 Creating token validation middleware 9.2.3 Extending existing routes to handle account IDs 9.3 What we didn’t cover Summary 10 Deploy your application 10.1 Setting up your application through environment variables 10.1.1 Set up config files 10.1.2 Accept command-line inputs for your application 10.1.3 Read and parse environment variables into your web service 10.2 Compiling your web service for different environments 10.2.1 Development vs. release flag when building your binary 10.2.2 Cross-compile your binary for different environments 10.3 Using build.rs in your build process 10.4 Creating the right Docker image for your web service 10.4.1 Create a statically linked Docker image 10.4.2 Set up a local Docker environment with docker-compose 10.4.3 Extract the configuration of the web server into a new module Summary 11 Testing your Rust application 11.1 Unit testing our business logic 11.1.1 Testing the pagination logic and dealing with custom errors 11.1.2 Testing the Config module with environment variables 11.1.3 Testing the profanity module with a newly created mock server 11.2 Testing our Warp filters 11.3 Creating an integration testing setup 11.3.1 Splitting up the codebase into a lib.rs and a binary 11.3.2 Creating the integration-test crate and the oneshot server implementation 11.3.3 Adding the registration test 11.3.4 Unwinding in case of an error 11.3.5 Testing the login and posting questions Summary Appendix—Thinking about security A.1 Verify your dependencies for security issues A.2 Verify your own code A.3 Closing words index Symbols Numerics A B C D E F G H I J K L M N O P Q R S T U V W
Donate to keep this site alive
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.