Rust Web Development with Rocket: A practical guide to starting your journey in Rust web development using the Rocket framework

Rust Web Development with Rocket: A practical guide to starting your journey in Rust web development using the Rocket framework

Rust Web Development with Rocket: A practical guide to starting your journey in Rust web development using the Rocket framework
Автор: Murti Karuna
Дата выхода: 2022
Издательство: Packt Publishing Limited
Количество страниц: 420
Размер файла: 1.8 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы  Дополнительные материалы 

Cover....1

Copyright....3

Contributors....5

Table of Contents....8

Preface....14

Part 1: An Introduction to the Rust Programming Language and the Rocket Web Framework....20

Chapter 1: Introducing the Rust Language....22

Technical requirements....23

An overview of the Rust language....23

Why use the Rust language?....24

Installing the Rust compiler toolchain....28

Installing rustup on the Linux OS or macOS....28

Installing a different toolchain and components....29

Updating the toolchain, rustup, and components....30

Writing Hello World!....30

Writing a more complex program....31

Packages and Cargo....39

Cargo package layout....39

Using third-party crates....43

Tools and getting help....51

Tools....51

Text editor....52

Getting help and documentation....52

Summary....53

Chapter 2: Building Our First Rocket Web Application....54

Technical requirements....55

Introducing Rocket – a web framework written in the Rust language....55

The HTTP request life cycle in Rocket....56

Rocket launch sequence....56

Creating our first Rocket web application....57

An asynchronous application....62

Configuring our Rocket web application....63

Starting the Rocket application in different profiles....63

Configuring the Rocket web application....65

Configuring the Rocket application using Rocket.toml....67

Overriding the configuration with environment variables....70

Getting help....71

Summary....71

Chapter 3: Rocket Requests and Responses....72

Technical requirements....73

Understanding Rocket routes....73

HTTP methods....74

URI....74

Path....75

Query....78

Rank....78

Format....80

Data....82

Implementing route handlers....83

Creating responses....90

Wrapping Responder....93

Built-in implementations....97

Making default error catchers....98

Summary....101

Chapter 4: Building, Igniting, and Launching Rocket....102

Technical requirements....103

Managing state....103

Working with a database....107

Attaching Rocket fairings....118

Rocket phases....118

Fairing callbacks....120

Implementing and attaching fairings....122

Connecting to a database using rocket_db_pools....127

Summary....130

Chapter 5: Designing a User-Generated Application....132

Technical requirements....133

Designing a user-generated web application....133

Planning the user struct....134

Creating user routes....137

Making user-generated contents....142

Finalizing the application....145

Modularizing the Rocket application....147

Summary....160

Part 2: An In-Depth Look at Rocket Web Application Development....162

Chapter 6: Implementing User CRUD....164

Technical requirements....165

Implementing GET user....165

Implementing GET users....170

Implementing POST user....177

Implementing PUT and PATCH user....189

Implementing DELETE user....197

Summary....200

Chapter 7: Handling Errors in Rust and Rocket....202

Technical requirements....203

Using panic!....203

Catching panic!....204

Using shutdown....205

Using Option....206

Returning Result....210

Creating a custom error type....213

Logging errors....219

Summary....222

Chapter 8: Serving Static Assets and Templates....224

Technical requirements....225

Serving static assets....225

Introducing the Tera template....227

Showcasing users....230

Working with forms....237

Securing HTML forms from CSRF....242

Summary....250

Chapter 9: Displaying Users' Post....252

Technical requirements....253

Displaying posts – text, photo, and video....253

Using generic data types and trait bounds....267

Learning about ownership and moving....270

Borrowing and lifetime....275

Implementing borrowing and lifetime....276

Summary....283

Chapter 10: Uploading and Processing Posts....284

Technical requirements....285

Uploading a text post....285

Uploading a photo post....292

Processing files asynchronously....298

Uploading a video post and process using a worker....303

Summary....313

Chapter 11: Securing and Adding an API and JSON....314

Technical requirements....315

Authenticating users....315

Authorizing users....326

Handling JSON....331

Protecting the API with a JWT....335

Summary....343

Part 3: Finishing the Rust Web Application Development....344

Chapter 12: Testing Your Application....346

Technical requirements....346

Testing the Rust program....347

Testing the Rocket application....352

Debugging the Rust application....359

Summary....363

Chapter 13: Launching a Rocket Application....364

Technical requirements....365

Optimizing production binaries....365

Setting up the Apache HTTP Server with a Rocket application....367

Generating Docker images for a Rocket application....372

Summary....375

Chapter 14: Building a Full Stack Application....376

Technical requirements....377

Introducing WebAssembly....377

Setting up a Cargo workspace....378

Setting a WebAssembly build target....379

Writing a WebAssembly application using Yew....380

Serving a WebAssembly application using Rocket ....390

Summary....392

Chapter 15: Improving the Rocket Application....394

Technical requirements....395

Extending the Rocket application....395

Adding logging....395

Expanding logging to tracing....395

Setting monitoring....397

Setting up a mailing and alerting system....398

Scaling the Rocket application....399

Exploring alternative Rust web frameworks....402

Actix Web....402

Tide....403

Warp....404

Summary....405

Index....408

Other Books You May Enjoy....417

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.


Похожее:

Список отзывов:

Нет отзывов к книге.