Rust Web Development with Rocket

Book description

Explore the world of Rocket-fueled web application development and the power of the Rust programming language

Key Features

  • Discover solutions to the common problems faced while creating web applications with Rocket
  • Learn everything about Rust, from structs and crates to generics and debugging
  • Combine Rust and Rocket to create, test, and deploy a full-featured web app

Book Description

Looking for a fast, powerful, and intuitive framework to build web applications? This Rust book will help you kickstart your web development journey and take your Rust programming skills to the next level as you uncover the power of Rocket - a fast, flexible, and fun framework powered by Rust.

Rust Web Development with Rocket wastes no time in getting you up to speed with what Rust is and how to use it. You'll discover what makes it so productive and reliable, eventually mastering all of the concepts you need to play with the Rocket framework while developing a wide set of web development skills. Throughout this book, you'll be able to walk through a hands-on project, covering everything that goes into making advanced web applications, and get to grips with the ins and outs of Rocket development, including error handling, Rust vectors, and wrappers. You'll also learn how to use synchronous and asynchronous programming to improve application performance and make processing user content easy.

By the end of the book, you'll have answers to all your questions about creating a web application using the Rust language and the Rocket web framework.

What you will learn

  • Master the basics of Rust, such as its syntax, packages, and tools
  • Get to grips with Rocket's tooling and ecosystem
  • Extend your Rocket applications using Rust and third-party libraries
  • Create a full-fledged web app with Rocket that handles user content
  • Write pattern-matching logic and handle Rust object lifetimes
  • Use APIs and async programming to make your apps secure and reliable
  • Test your Rocket application and deploy it to production
  • Containerize and scale your applications for maximum efficiency

Who this book is for

This web development book is for software engineers who want to learn how to use the Rocket framework to build web applications. Although not mandatory, basic knowledge of the Rust programming language will help you understand the topics covered easily.

Table of contents

  1. Rust Web Development with Rocket
  2. Contributors
  3. About the author
  4. About the reviewer
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  6. Part 1: An Introduction to the Rust Programming Language and the Rocket Web Framework
  7. Chapter 1: Introducing the Rust Language
    1. Technical requirements
    2. An overview of the Rust language
      1. Why use the Rust language?
    3. Installing the Rust compiler toolchain
      1. Installing rustup on the Linux OS or macOS
      2. Installing a different toolchain and components
      3. Updating the toolchain, rustup, and components
    4. Writing Hello World!
      1. Writing a more complex program
    5. Packages and Cargo
      1. Cargo package layout
      2. Using third-party crates
    6. Tools and getting help
      1. Tools
      2. Text editor
      3. Getting help and documentation
    7. Summary
  8. Chapter 2: Building Our First Rocket Web Application
    1. Technical requirements
    2. Introducing Rocket – a web framework written in the Rust language
      1. The HTTP request life cycle in Rocket
      2. Rocket launch sequence
    3. Creating our first Rocket web application
      1. An asynchronous application
    4. Configuring our Rocket web application
      1. Starting the Rocket application in different profiles
      2. Configuring the Rocket web application
      3. Configuring the Rocket application using Rocket.toml
      4. Overriding the configuration with environment variables
    5. Getting help
    6. Summary
  9. Chapter 3: Rocket Requests and Responses
    1. Technical requirements
    2. Understanding Rocket routes
      1. HTTP methods
      2. URI
      3. Path
      4. Query
      5. Rank
      6. Format
      7. Data
    3. Implementing route handlers
    4. Creating responses
      1. Wrapping Responder
      2. Built-in implementations
    5. Making default error catchers
    6. Summary
  10. Chapter 4: Building, Igniting, and Launching Rocket
    1. Technical requirements
    2. Managing state
    3. Working with a database
    4. Attaching Rocket fairings
      1. Rocket phases
      2. Fairing callbacks
      3. Implementing and attaching fairings
      4. Connecting to a database using rocket_db_pools
    5. Summary
  11. Chapter 5: Designing a User-Generated Application
    1. Technical requirements
    2. Designing a user-generated web application
      1. Planning the user struct
      2. Creating user routes
      3. Making user-generated contents
      4. Finalizing the application
    3. Modularizing the Rocket application
    4. Summary
  12. Part 2: An In-Depth Look at Rocket Web Application Development
  13. Chapter 6: Implementing User CRUD
    1. Technical requirements
    2. Implementing GET user
    3. Implementing GET users
    4. Implementing POST user
    5. Implementing PUT and PATCH user
    6. Implementing DELETE user
    7. Summary
  14. Chapter 7: Handling Errors in Rust and Rocket
    1. Technical requirements
    2. Using panic!
      1. Catching panic!
      2. Using shutdown
    3. Using Option
    4. Returning Result
    5. Creating a custom error type
    6. Logging errors
    7. Summary
  15. Chapter 8: Serving Static Assets and Templates
    1. Technical requirements
    2. Serving static assets
    3. Introducing the Tera template
    4. Showcasing users
    5. Working with forms
    6. Securing HTML forms from CSRF
    7. Summary
  16. Chapter 9: Displaying Users' Post
    1. Technical requirements
    2. Displaying posts – text, photo, and video
    3. Using generic data types and trait bounds
    4. Learning about ownership and moving
    5. Borrowing and lifetime
      1. Implementing borrowing and lifetime
    6. Summary
  17. Chapter 10: Uploading and Processing Posts
    1. Technical requirements
    2. Uploading a text post
    3. Uploading a photo post
    4. Processing files asynchronously
    5. Uploading a video post and process using a worker
    6. Summary
  18. Chapter 11: Securing and Adding an API and JSON
    1. Technical requirements
    2. Authenticating users
    3. Authorizing users
    4. Handling JSON
    5. Protecting the API with a JWT
    6. Summary
  19. Part 3: Finishing the Rust Web Application Development
  20. Chapter 12: Testing Your Application
    1. Technical requirements
    2. Testing the Rust program
    3. Testing the Rocket application
    4. Debugging the Rust application
    5. Summary
  21. Chapter 13: Launching a Rocket Application
    1. Technical requirements
    2. Optimizing production binaries
    3. Setting up the Apache HTTP Server with a Rocket application
    4. Generating Docker images for a Rocket application
    5. Summary
  22. Chapter 14: Building a Full Stack Application
    1. Technical requirements
    2. Introducing WebAssembly
    3. Setting up a Cargo workspace
    4. Setting a WebAssembly build target
    5. Writing a WebAssembly application using Yew
    6. Serving a WebAssembly application using Rocket
    7. Summary
  23. Chapter 15: Improving the Rocket Application
    1. Technical requirements
    2. Extending the Rocket application
      1. Adding logging
      2. Expanding logging to tracing
      3. Setting monitoring
      4. Setting up a mailing and alerting system
    3. Scaling the Rocket application
    4. Exploring alternative Rust web frameworks
      1. Actix Web
      2. Tide
    5. Warp
    6. Summary
    7. Why subscribe?
  24. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Rust Web Development with Rocket
  • Author(s): Karuna Murti
  • Release date: June 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781800561304