In this episode, we’ll dive into some Rust production coding. Starting from where we left off in the Rust Axum Full Course, we’ll scale it up to a production-ready web application code base. Over the course of 9 chapters, we’ll tackle tracing, configuration, and the model layer with PostgreSQL. Then, we’ll delve into password encryption and secure web tokens, end with a JSON-based RPC implementation.

This marks the beginning of many exciting series on Rust production coding. Feel free to ask questions, provide feedback, and join us on Discord (https://discord.gg/XuKWrNGKpC). Until next one, happy coding!

More info on the Rust Web App (github, discord, and design doc): https://rust10x.com/web-app

Previous video – Axum Full Course – https://youtube.com/watch?v=XZtlD_m59sM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q

GitHub Code: https://github.com/rust10x/rust-web-app (MIT or Apache 2.0, all free to use)

Big thanks to CrabNebula (https://crabnebula.dev/) for their sponsorship.

Help support this channel about production coding in Rust: https://patreon.com/jeremychone.

Content:

– 00:00:00 – INTRO
– 00:01:00 – E01-C01 – Baseline
– 00:09:50 – E01-C02 – Tracing (basics)
– 00:14:26 – E01-C03 – Config
– 00:21:17 – E01-C04 – DB Live Reload
– 00:39:48 – E01-C05 – Model 1/2 – Task CRUD
– 01:18:55 – E01-C06 – Model 2/2 – Shared Impl
– 01:44:00 – E01-C07 – Pwd Encrypt & Validation
– 02:22:21 – E01-C08 – Secure Token & Web Auth
– 03:14:45 – E01-C09 – RPC (JSON-RPC)

#RustProgramming #RustLang #WebDevelopment #completecourse

Tech notes:

– `cargo install cargo-watch` – If you haven’t already, make sure to install Cargo Watch.
– This project currently utilizes sqlx 0.6.x. Although sqlx 0.7.1 is available, it appears to have timeout issues with some of the unit tests. I’m looking into this problem and will upgrade once it’s resolved. In the meantime, for a seamless experience, please use sqlx 0.6 and sqb 0.3.

Jeremy Chone:

– Twitter – https://twitter.com/jeremychone
– Discord General Rust – https://discord.gg/W2besKCzjx
– Discord Rust10x – https://discord.gg/XuKWrNGKpC
– Patreon – https://patreon.com/jeremychone

Other popular Rust Programming videos:

– Rust Axum Full Course – https://www.youtube.com/watch?v=XZtlD_m59sM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Rust Type State Builder Pattern – https://www.youtube.com/watch?v=pwmIQzLuYl0&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Rust Builder Pattern – https://www.youtube.com/watch?v=Z_3WOSiYYFY&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Rust Builder Pattern – https://www.youtube.com/watch?v=Z_3WOSiYYFY&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Quick Start Code Layout – https://www.youtube.com/watch?v=oxx7MmN4Ib0&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– AWESOME-APP (Rust10x) Full Overview – Rust template for building Awesome Desktop Application: https://www.youtube.com/watch?v=BY_ZjPGqJJk&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Tauri Quick Introduction (Desktop App wit Rust Programming): https://www.youtube.com/watch?v=kRoGYgAuZQE&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Rust Bevy Full Tutorial – Game Development with Rust: https://www.youtube.com/watch?v=j7qHwb7geIM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Rust for Java Developers series: https://www.youtube.com/watch?v=iFdh4sPC5Tg&list=PL7r-PXl6ZPcD63DS2djSiz4SlXkaTfobc&index=2&t=654s

Playlists:

– Rust For Desktop App: https://youtube.com/playlist?list=PL7r-PXl6ZPcAQAi1lfVrtHCSbaJbwZ4O8
– Everything Rust Programming – Tutorials, Courses, Tips, Examples: https://youtube.com/playlist?list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
– Rust Programming for Web Development: https://youtube.com/playlist?list=PL7r-PXl6ZPcCLvwpdD2Vj1O4CyoFTiHKd

Rust10x ➜ https://rust10x.com – Production code templates.

Rust10x GitHub – https://github.com/rust10x

Tool used:

– ScreenBrush on Mac App Store (Gromit seems to be the equivalent on Linux)
– Recut for audio flow.
– Izotope RX for de-mclick and dessing.
– Davinci Resolve as video editing.

source

28 Comments

  1. Jeremy, another idea for this series would be implementing more Managers, services, etc, outside of ModelManager. Something like remote apis, because sometimes we need an external service request.
    I'm building a backend in RUST with JSONRPC using your architecture and I'm struggling with how to struct differents managers and how to handle it inside my Rpc methods.

    I know that with Axum we usually build an AppState that stores everything and pass it to our routes, but as we only have "one" route ("/rpc"), but different methods (task_create, task_update, etc), not always we'ill use everything the AppState provides. For example, let's suppose that `method_a` uses XManager, `method_b` only uses YManager and `method_c` uses both of them.
    With a linear search it can be managed very well, but the problem comes when you try to implement a registration to the rpc methods.

    I think that will show very well the use of traits, generics, futures handling, project structures, etc.

    Thanks for the videos!

  2. Hello, I'm having some trouble with postgres start up. I clone github rep and run commands in the README:
    – cargo watch -q -c -w src/ -w .cargo/ -x "run"
    – docker run –rm –name pg -p 5432:5432 -e POSTGRES_PASSWORD=welcome postgres:15

    Code panicked at unwrap:
    INIT.get_or_init(|| async {

    info!("{:<12} – init_dev_all()", "FOR-DEV-ONLY");

    dev_db::init_dev_db().await.unwrap(); // <<<<< HERE

    })

    Saying: "thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Database(PgDatabaseError { severity: Fatal, code: "28P01", message: "password authentication failed for user "postgres"", …… , file: Some("auth.c"), line: Some(285), routine: Some("auth_failed") })', src_dev_utilsmod.rs:21:37"

    When I inspect container, there is indeed env POSTGRES_PASSWORD = welcome.

    I literally just did what Jeremy did, so I'm hopeless.
    Some ideas on how to fix it? Thank you.

  3. Jeremy, about the tests for Bmc (TaskBmc), I came across an error with tokio runtime. It seems that running some tests together crash the runtime and some tests fail randomly. Did it happen with you?

    An error message example:

    running 4 tests
    test model::user::user_bmc_tests::test_get_err_not_found … ok
    test model::user::user_bmc_tests::test_delete_err_not_found … ok
    test model::user::user_bmc_tests::test_get_ok … ok
    test model::user::user_bmc_tests::test_update_ok … FAILED

    failures:

    —- model::user::user_bmc_tests::test_update_ok stdout —-
    thread 'model::user::user_bmc_tests::test_update_ok' panicked at 'assertion failed: `(left == right)`
    left: `0`,
    right: `1`', /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/runtime/io/scheduled_io.rs:220:9
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

  4. This is such an amazing resource! I am new to “production” API architecture and I was just wondering where I can read more about this particular architecture? (Web, context, event, model etc). Or if you have any resources for other API architectures you like. Keep up the absolutely spectacular work

  5. Great video Jeremy. About the JSONRPC, you did a linear search approach. What about a project with alot of namespaces and methods? What's the best way to handle every possible method?

  6. Really nice video ! I really like all the explaination on why we do things like these instead of another manner. I started to improve the project on my side so that i will compare with your solution on the next videos, i started with tracing and exposing metrics for prometheus. I juste have a questions about the model layer. I am not a big fan of ORM but for nested entities I didn't found good implementations to do it with sqlx. What are you thoutgh on that, do you have any ressources that could help me ?

  7. Fantastic video! So glad that I found you since I am learning rust and do not have that much web/server experience. Found a lot of things that I can improve in my axum server. Keep it up, instantly subscribed!

  8. 1:36:45 in this chapter you use sqlb crate to build sql queries, why not use something like diesel or sea-orm for this ? what downsides to using orm instead of direct sql queries?
    great series btw, very nice video.

  9. You can really feel the passion and the amount of dedication that went into this. Very unique here on YouTube. I hope you'll continue to be able to produce high quality content like this full time. ❤

  10. Your videos and explanations are amazing. It would be really great to see integrations when it comes to auth for this example with real world providers developers use like auth0, azure or other oauth providers.

Leave A Reply

Please enter your comment!
Please enter your name here