Rust Axum Production Coding (E01 - Rust Web App Production Coding)

  Рет қаралды 70,446

Jeremy Chone

Jeremy Chone

Күн бұрын

GitHub repo updated to Axum 0.7 github.com/rust10x/rust-web-app
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 ( / discord . Until next one, happy coding!
Episode 01 (This episode): • Rust Axum Production C...
Episode 02: • Rust Sea-Query + SQLX ...
Episode 03: • Rust Workspace Product...
More info on the Rust Web App (github, discord, and design doc): rust10x.com/web-app
Previous video - Axum Full Course - • Rust Axum Full Course ...
GitHub Code: github.com/rust10x/rust-web-app (MIT or Apache 2.0, all free to use)
Big thanks to CrabNebula (crabnebula.dev/) for their sponsorship.
Help support this channel about production coding in Rust: / 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 - / jeremychone
- Discord General Rust - / discord
- Discord Rust10x - / discord
- Patreon - / jeremychone
Other popular Rust Programming videos:
- Rust Axum Full Course - • Rust Axum Full Course ...
- Rust Type State Builder Pattern - • Rust Programming: Type...
- Rust Builder Pattern - • Rust Programming: The ...
- Rust Builder Pattern - • Rust Programming: The ...
- Quick Start Code Layout - • Rust - Simple Code Lay...
- AWESOME-APP (Rust10x) Full Overview - Rust template for building Awesome Desktop Application: • Building Awesome Deskt...
- Tauri Quick Introduction (Desktop App wit Rust Programming): • Rust Tauri 1.0 - Quick...
- Rust Bevy Full Tutorial - Game Development with Rust: • Rust Bevy Full Tutoria...
- Rust for Java Developers series: • Rust for Java Develope...
Playlists:
- Rust For Desktop App: • Rust Programming for D...
- Everything Rust Programming - Tutorials, Courses, Tips, Examples: • Everything Rust Progra...
- Rust Programming for Web Development: • Rust Programming for W...
Rust10x ➜ rust10x.com - Production code templates.
Rust10x GitHub - 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.

Пікірлер: 153
@peterklemenc6194
@peterklemenc6194 8 ай бұрын
As a Rust beginner, am taking my sweet time slowly going through all these videos, they are more than a gold mine. Really appreciate all the effort you've put into these series!
@snk-js
@snk-js 8 ай бұрын
me too, this dude is an angel
@cryoexn7307
@cryoexn7307 7 ай бұрын
I think this has to be one of the best tutorials I’ve ever watched…
@dran1x
@dran1x 11 ай бұрын
This video needs a lot more attention.
@pablovigliero1275
@pablovigliero1275 10 ай бұрын
This is awesome man! Pure gold content. Thanks for all the effort you've put making the app, explaining what you´re doing and editing the video!
@FernandoCelestino-DataVirtus
@FernandoCelestino-DataVirtus 4 ай бұрын
I feel like giving a little testimony. Finally after weeks of coding along, stopping, hovering with the mouse in VSCode to read docs of used rust constructs, studying to understand the code, and trying to do things before you, so that i could know i was really learning, i finished this one. Unbelievable how much knowledge i got, not only in rust, but in backend best practices in general, and how robust is the basis provided by the code of this lesson, along with the rust axum course, and the follow up episote 2 (Sql builder with modql). The final part with declarative macros was a grand finale, since i had never built something usefull with macros, and finally saw a simple and useful application, that i can replicate to other situations. I feel like getting up and giving a round of applause. Thanks a lot for that. I will use the base i constructed so far from your code to build a production web service in an ongoing project.
@JeremyChone
@JeremyChone 4 ай бұрын
Awesome! Thanks for taking the time to share your experience.
@kameikojirou
@kameikojirou 11 ай бұрын
This is Fantastic! Thank you so much for all you do for the Rust Community!
@DerMigi
@DerMigi 10 ай бұрын
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!
@prashlovessamosa
@prashlovessamosa 11 ай бұрын
Good to see you back thanks for Rusty teachings.
@engdoretto
@engdoretto 11 ай бұрын
The best rust channel with hands-on tutorials! Thank you!!!
@maxali6591
@maxali6591 11 ай бұрын
Elles sont excellentes tes vidéos merci de pousser autant la technicité. Prend ton temps, ce contenu est excellent !
@Rustby
@Rustby 11 ай бұрын
Thank you so much Jeremy! Awesome video as always 🎉
@chaqua1559
@chaqua1559 11 ай бұрын
I LOVE your videos. Even tho Rust is the hardest language I learned yet, it still is way to interesting to give up, and your videos are helping A LOT.
@TheBabooner
@TheBabooner 4 ай бұрын
This is a whole new level of excellence. Merci!
@ItaloMaiaTM
@ItaloMaiaTM 7 ай бұрын
Loved the unit-test approach discussion. The different approaches to unit-test are not discussed enough. It is good to see some light being shed into it.
@sinaebr7337
@sinaebr7337 11 ай бұрын
i marked previous episode to see after my current job done. it will be done in about three weeks and I will have 5 hours of wonderful videos to enjoy and learn thanks ❤
@herrbanane
@herrbanane 10 ай бұрын
You can really feel the passion and the amount of dedication that went into this. Very unique here on KZfaq. I hope you'll continue to be able to produce high quality content like this full time. ❤
@nomadperson4619
@nomadperson4619 11 ай бұрын
great course. We are lucky to have people like you and johnhoo :)
@hnazmul
@hnazmul 8 ай бұрын
Wow.. Very happy to see your reguler Rust video... We are so lucky that we got you.
@iwansyahp
@iwansyahp 10 ай бұрын
thank you, learnt alot from you! I love the way you teach, easy to follow. did not expect I can finish in a session.
@JeremyChone
@JeremyChone 10 ай бұрын
Impressive that you finished in one session.
@ruggerorebellato
@ruggerorebellato 10 ай бұрын
I never comment on KZfaq, this is a masterpiece, thank you, you made the difference.
@jdery99
@jdery99 10 ай бұрын
Thank you a lot for the videos and your contribution to the Rust community as a whole. Small suggestions: - "thiserror" crate instead of implementing the Error boilerplate - "clap" crate for the configuration part
@AchwaqKhalid
@AchwaqKhalid 11 ай бұрын
The way this was explained.... WoW 👏👏👏👏👏👏
@selvarajs.7494
@selvarajs.7494 5 ай бұрын
comprehensive and high quality content.
@irlshrek
@irlshrek 11 ай бұрын
So excited!! Can't wait to work though this!
@sunhsiang6644
@sunhsiang6644 10 ай бұрын
The best video of AXUM !
@mishadaley
@mishadaley 11 ай бұрын
Hello Jeremy, (French here) Thank you very much for the quality of your videos on Rust, especially this one! They are very structured; all the explanations are clear yet comprehensive; and even though the project seems simple at first sight, you managed to provide us with so many concepts and best practices. That’s really a masterpiece of a job! All the best for your future videos ;)
@JeremyChone
@JeremyChone 11 ай бұрын
Thank you for the very nice feedback.
@ItaloMaiaTM
@ItaloMaiaTM 8 ай бұрын
Wow, this is massive! Time to dive into rust once more.
@jorgeosorio1613
@jorgeosorio1613 11 ай бұрын
thanks a lot jeremy for all you do man.
@mhemaungthuwin7916
@mhemaungthuwin7916 4 ай бұрын
This is what I am looking for dude. Thanks a lot.
@stephenbluck2698
@stephenbluck2698 10 ай бұрын
Great video! Looking forward to the next one.
@cheebadigga4092
@cheebadigga4092 6 ай бұрын
Thank you so so so much for these videos! Helps a lot with architecture stuff!!
@KNTH01
@KNTH01 11 ай бұрын
Thanks for making these videos!
@HagbardCelineOnRust
@HagbardCelineOnRust 10 ай бұрын
Hi Jeremy. It is so nice to see another of your courses. Hopefully i will find the time soon to follow you. lf 2 it. keep up the good work
@dani5318
@dani5318 11 ай бұрын
Love your videos, so good.
@LinuxForLife
@LinuxForLife 11 ай бұрын
Nice! Eager to code along to improve my knowledge. Thank you!
@NeotenicApe
@NeotenicApe 10 ай бұрын
Incredible, every time ❤
@lostsocket
@lostsocket 11 ай бұрын
Incredible quality! 1000000000000000000000000000000000000000000000 thanks for sharing this knowledge!!
@TN19N
@TN19N 7 ай бұрын
This captures the best practices for coding the backend, applicable to all languages, not just Rust. Thanks a lot!
@user-rl5mz5cg3w
@user-rl5mz5cg3w 2 ай бұрын
I paid a year's membership to show appreciation for such great work. I hope viewers will not just spread the word but also chip in to show their support.
@JeremyChone
@JeremyChone 2 ай бұрын
Thank you so much for your support and comment. More cool stuff is coming...
@user-tw3do4xk3f
@user-tw3do4xk3f 10 ай бұрын
I learned a lot from your video!非常感谢!我要试着写一遍代码了!
@AIExEy
@AIExEy 5 ай бұрын
Most underrated rust creator
@emvdl
@emvdl 11 ай бұрын
Thanks, well done Jeremy 👍🙌
@suhrobmalikov
@suhrobmalikov 11 ай бұрын
this is what I need. thank you
@zaafhachemrachid1701
@zaafhachemrachid1701 11 ай бұрын
You back ❤🎉🎉🎉
@shanecole401
@shanecole401 11 ай бұрын
Great video- learned a lot
@jaredthanemartin
@jaredthanemartin 6 ай бұрын
Wonderful video. Thanks
@b1chler
@b1chler 11 ай бұрын
Really cool! ❤
@SamirMamude
@SamirMamude 6 ай бұрын
Amazing tutorial! Thank you very much!
@tony-go-code
@tony-go-code 9 ай бұрын
Wow! This is great, thank you, like Rust, like your tutorial.
@riigel
@riigel 11 ай бұрын
GREAT!! 🎉🎉🎉
@PublicAccount0
@PublicAccount0 9 ай бұрын
well played, started to watch.
@blainewordly9134
@blainewordly9134 10 ай бұрын
Fantastic ❤
@renbrek
@renbrek 11 ай бұрын
awesome!
@jrcentralcoastmagician3333
@jrcentralcoastmagician3333 10 ай бұрын
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
@undefined24
@undefined24 9 ай бұрын
Thank you so much sir
11 ай бұрын
WHAAAAT?! THANK YOU!!
@kashnigahbaruda
@kashnigahbaruda 8 ай бұрын
Legend
@Tszyu01
@Tszyu01 11 ай бұрын
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.
@JeremyChone
@JeremyChone 11 ай бұрын
Yes, in a future episode we will talk OAuth, probably with Google and/or GitHub as an example.
@patatasdelpapa
@patatasdelpapa 9 ай бұрын
Some thoughs of mine while doing the course. - I had a much nicer experience using tokio's Semaphore to synchronize test than serial_test. - Because I didn't read the description I used sqlx 0.7 and my test failed so I removed the static pool and instead made a new pool with 1 connection for each test then passing that pool to the ModelManager and continuing the tests as normal. I'm currently in E01-C05 - Model 1/2 - Task CRUD so I expect to make some other changes but otherwise pretty good tutorial so far.
@JeremyChone
@JeremyChone 9 ай бұрын
Thanks for the feedback. On the latest main branch, I put the fix/workaround for SQLx 0.7, which is to set max_connections = 1 for testing. It's not ideal, but it works until they fix the issue. Latest main branch: github.com/rust10x/rust-web-app Also, feel free to join the Discord. Discord: discord.gg/XuKWrNGKpC I am working on episode e02, where we've moved to sea-query and more modql. Work is still underway, but it's the next level and will be the prep for the second episode. Serial testing is required due to the brute-force database reset approach. It could be removed with some work. When to undertake that work depends on preferences/priorities. But it's potentially valid to do in some cases.
@FelipeSilva-ok7uz
@FelipeSilva-ok7uz 10 ай бұрын
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!
@JeremyChone
@JeremyChone 10 ай бұрын
This is an interesting topic, and I would love to have a discussion with you about it. If you have time, I would love to chat about this in our Discord: discord.gg/XuKWrNGKpC In short, yes, the application blueprint will eventually have multiple clients inside the ModelManager, but I am not sure we need multiple of them. However, I am definitely interested in discussing the pros and cons.
@diehenne
@diehenne 11 ай бұрын
❤❤❤❤
@KokoKoko-hz9cd
@KokoKoko-hz9cd 5 ай бұрын
@victorgxn
@victorgxn Ай бұрын
More axum content
@algo-zq1vu
@algo-zq1vu 3 ай бұрын
I'm running into problems in E01-C04 - DB Live Reload - when running the docker container (works) and starting up the app, the SQL statements get executed locally rather than in the docker container (very new to this, sorry if I'm using terminology wrong). This means, I can see the newly (re)created database + tables when checking into psql locally, but when executing psql in the docker container, there are no changes (just the default users/dbs). If anyone can help with this, greatly appreciated. Spent a whole day just figuring out what's not working properly, ay!
@kaporos
@kaporos 11 ай бұрын
Hey ! Thanks for this amazing vid ! I just didn't understand why you want to make a distinction between ModelManager and ModelControler
@JeremyChone
@JeremyChone 11 ай бұрын
Great question. Here is a first pass at the answer. I also added this as the first FAQ question. Decoupling the construct that performs the task (i.e., ModelController) from the one that provides the resources (i.e., ModelManager) has the following benefits: 1. Keeps the ModelController design and requirements more focused on its function, which is to perform data changes. 2. Keeping the ModelController construct stateless greatly simplifies "specialization" implementation (see `model::base`). 3. Allows the management of the resources (typically in App State) to evolve separately while minimizing impact on the model controller (and vice versa). In short, this separation of concerns allows both parts to stay more focused on their respective functions and to evolve separately while minimizing how they affect each other. As the application's needs grow, these patterns can evolve, and further separation of concerns may be needed. However, this is a good base to start with, balancing simplicity and future code scalability. Congrats, you are the first in the FAQ: awesomeapp.dev/rust-web-app/#why-distinguish-between-the-modelmanager-and-modelcontroller
@JeremyChone
@JeremyChone 11 ай бұрын
Btw, I just updated the answer in the FAQ with the text below. And also, I am planning to do a quick video to go over those points. Let me know if you have an handle (youtube, x, github) you want me to use to refer you (as you want). Thanks again for this great question. I hope it is getting answered: === Anwser - The short answer is because it makes each component much simpler and more focused on executing its core function. - For example, now the ModelControllers do not need any states, and therefore, their design becomes simpler as they are merely a set of functions with some common contracts. - We do not have to worry about ModelControllers' instantiation, ownership, lifetime, or anything of this nature in our design. - So, we know that everything that would be state-related will be passed as an argument in a consistent manner. - And in fact, that goes for the Ctx as well, - And that simplicity allowed us to design the base shared CRUD implementation just as a set of static functions. - Conversely, the ModelManager now can just focus on holding and managing the appropriate resources that might be needed by the various - ModelControllers, irrespective of the specific operations. - Right now, it is a very simple implementation, but it will become richer when we add more client types and database transaction support.
@kaporos
@kaporos 11 ай бұрын
@@JeremyChone wow ! I wasn't expecting such a good response ! it was pretty clear, thank you ! (and you can call me simply kaporos, but you dont have to ahah)
@JeremyChone
@JeremyChone 11 ай бұрын
@@kaporos I am making a video about this question. It came up couple of times, and it is an important point.
@nikolatotev
@nikolatotev 11 ай бұрын
Fantastic video extremely nice to see some production level coding! I have some quest ions about the IDE setup, how do you do the //region bits together and how do you setup those snippets you use?
@JeremyChone
@JeremyChone 11 ай бұрын
It's just a code snippet that I bind to ctrl+c. Go to configure snippet for rust language `User/snippets/rust.json` "comment-section": { "prefix": "cc", "body": [ "// region: --- ${1:Section}", "${2}$TM_SELECTED_TEXT", "// endregion: --- ${1:Section}" ], "description": "Comment Section" }, keybinding `User/bindings.json` { "key": "ctrl+c", "command": "editor.action.insertSnippet", "when": "editorTextFocus", "args": { "name": "comment-section" } },
@nikolatotev
@nikolatotev 11 ай бұрын
@@JeremyChoneAha! very nice I'll try it out! I'm currently following along with the video to make this project myself and this will be helpful. I really like the insights when it comes to architecture design of a web app.
@alexandruolaru7855
@alexandruolaru7855 8 ай бұрын
That's an awesome course, and I even finished it, took me a couple of weeks with pauses and typing myself the code, but have a couple of questions: 1. Why for token you decided to implement from scratch as JWT has pretty much the same structure, goal and it's already an industry standard? 2. Why no diesel for migrations ? 3. JSON-RPC seems a fun way to go but is there content on how to create a graph-ql transport for the same BMC's ? Thank you again for your invaluable input and making us greater engineers! Some maybe suggestions for the structure: I had troubles to navigate forward and backward in the video as each mouse click will be pretty much 5-10 minutes of content.
@JeremyChone
@JeremyChone 8 ай бұрын
Those are good questions. I wanted to write the longer answer, but here is a relatively short one: 1) Secure Web Token vs. JWT: In our case, we assume the token is designed for interpretation solely by our system. Different services may exist, but they all belong to the same organization. Hence, we don't need to disclose the algorithm used, as sharing less is preferable. The design also aims to decouple Authorization from Authentication. The token is used to verify identity, but roles, privileges, and other aspects are better managed by an independent API and re-evaluated at the time of request. Roles/Privileges should be transactional, with tokens remaining valid longer than the period suitable for checking roles/privileges. Therefore, roles in JWT are more cosmetic than security-based. In distributed systems where we don't own all the systems, JWT might be acceptable, though many don't share keys. However, one shouldn't fully trust the roles defined in JWT. At its simplest and most secure, a token comprises three essential parts: - The identifier (e.g., username or user UUID), - The expiration time, - The signature, created with minimal information sharing. In summary, while JWT may be useful in a distributed context, in a multi-service system we own, adopting a minimalistic approach with less information sharing reduces the attack surface and enforces transactional access control. 2) Diesel for Migration: Our approach here differs. For large apps, 'Migration' or 'Evolution' (as we prefer to call it) is better managed as a sidecar service, rather than at the web-app level through the Database Driver or ORM. If our ORM or SQLX manages migration within our app code, we must determine which container instance is responsible. Only one instance should update the database schema. This indicates that the web server, typically scaling horizontally, should not be responsible for schema updates. This task is more suitably handled in a sidecar, a dedicated pod/container, and thus does not need to be integrated into the ORM, SQL Builder, or lower-level database drivers like SQL. 3) JSON-RPC & QL: Refer to Episode 02 (kzfaq.info/get/bejne/Y8p9e5yGzt2voZs.html) which discusses SEA-QUERY and MODQL for advanced JSON-based queries (JSON IN and JSON OUT). More exciting developments are forthcoming. You can also view a quick spec I developed on joql.org to see upcoming features (included in the specifications). Hope this makes sense. Our philosophy is not about reusing as many wheels as possible, but rather about using the right ones. Happy coding.
@alexandruolaru7855
@alexandruolaru7855 8 ай бұрын
@@JeremyChone thank you for the extended answer
@emanueley8410
@emanueley8410 7 ай бұрын
@@JeremyChone Wow, and that was the "short! answer :D 1) Very nice insight on the Secure Web Tokens vs JWT. 2) I'm looking forward to learn how you handle migrations/evolutions in a sidecar service Going through the comment section of your videos to find these answers is definetly worth it!
@FelipeSilva-ok7uz
@FelipeSilva-ok7uz 10 ай бұрын
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?
@JeremyChone
@JeremyChone 10 ай бұрын
Good question, and it is something I plan to address in the future. In the meantime, here are a few points to consider: 1) For a small number of API methods, say between 10 and 20, the current approach should suffice. After all, we would need a routing table regardless of the method adopted. Whether we are using macro rules or another strategy, it should work well. 2) As the number increases, it might become necessary to create sub-web modules, each responsible for registering their respective APIs. I envision adopting a builder/plugin approach somewhat akin to the "router" strategy utilized by Axum. 3) Firs I would explore the potential of leveraging the Tower service model to aid in this process. While I am cautious not to unnecessarily complicate the system just to "reuse a wheel," the Tower model might prove to be a good fit. I will investigate this at a later stage. 4) Some time ago, I created a video on constructing an Async Router ([watch here](kzfaq.info/get/bejne/r9WSpq-l2LO0fGw.html)). This might serve as a foundation if the Tower lib is not a fit. The goal prioritizes maintaining simplicity in the system, avoiding overly intricate solutions and focusing on meeting immediate needs. Currently, all RPC handlers can be normalized, as demonstrated, incorporating elements such as context (ctx), multimedia messaging (mm), and parameters (params), which simplifies the system considerably. While I do plan to develop such a design in the future, the existing design is scalable to around 20 methods. Beyond this point, the details become specific to web:rpc implementations, thereby having minimal impact on the rest of the code. I hope this provides some insight into your question.
@aimericsorindev253
@aimericsorindev253 10 ай бұрын
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 ?
@JeremyChone
@JeremyChone 10 ай бұрын
Sorry for the late answer. Yes, eventually I am going to show how to do nested/join (like project/task relationship). You would do join. For now, you will have to use raw sqlx, since sqlb does not support join yet.
@mottosson
@mottosson 11 ай бұрын
Will you make a video about deploying Rust applications as well? That would be great as a last part to this series.
@JeremyChone
@JeremyChone 11 ай бұрын
Yes, this is the plan. It will come a little bit later as this will be done via Kubernetes and will have multi service support.
@mottosson
@mottosson 11 ай бұрын
Amazing! Thanks a lot!
@gabrielcournelle3055
@gabrielcournelle3055 4 ай бұрын
Hi Jeremy, Thanks a lot for this great in depth tutorial. I learnt a lot. I have a question regarding middlewares. In mw_ctx_resolve, we only modify the request. Could we have used map_request_with_state instead of from_fn_with_state? If yes, what is the best practice? Is it better to chain middleware with from_fn or can we also chain the map_request/map_response middlewares?
@JeremyChone
@JeremyChone 4 ай бұрын
The code design approach allows for `Ctx` to be "injectable" into any Axum middleware or handler functions, enabling them to extract information or, eventually, add information to it. Since `Ctx` is designed to be per request, the appropriate Axum construct to use is Request Extractors. States are suitable for application-wide resources, such as the ModelManager (e.g., with some type of database client), and similar components. I hope this answers your question.
@gertrudessampaio8689
@gertrudessampaio8689 8 ай бұрын
Which vscode extension do you use for code snippets ?
@JeremyChone
@JeremyChone 7 ай бұрын
I finally took some time to create the Rust10x VSCode Extension and a webpage with information about my VSCode setup. Everything can be found here: rust10x.com/vscode
@haoy80
@haoy80 9 ай бұрын
Thank you so much for creating this video! It seems that every function in the model controller using "ctx", and "mm " as first two arguments. Why don't we create a model controller struct {ctx, mm} and implement these functions as "methods".
@JeremyChone
@JeremyChone 8 ай бұрын
Okay, this is a very good question, and usually, when we encounter repetitive patterns like this, they are good candidates for consolidation. First, let's clarify what each element is: `ctx` - This is designed to be the request/command context containing user information. Eventually, it will include on-demand PBAC (Privilege-Based Access Control) and other per-command contexts. The aim is to decouple it from the web layer, which will become more apparent in future episodes when we separate the web layer and the core layer (model, ctx, etc.) into their own sub-crate. `ModelManager` - This serves as the "model app state," where we have various clients (DBCon, S3Client, etc.) to communicate with different services. Since all BMC functions take both arguments, we might consider putting them into a single container construct to combine them. However, their responsibilities and usages are different, so the container construct would not have methods specific to sub-elements, allowing us to maintain the separation of concerns. This is why, for the time being, I have kept them separate. Other approaches are also valid as long as they provide a coherent narrative and stand the test of time.
@jimitsoni18
@jimitsoni18 7 ай бұрын
Hello Jeremy, i am facing an issue where some of my Task crud test randomly fail with PoolTimedOut error. which task fail is also random, and it is rare but there are also times where everything works perfectly, can you please help me with this issue?
@JeremyChone
@JeremyChone 7 ай бұрын
Yes, something changed in sqlx 0.7 that causes this issue when running tests. The trick is to set the DBPool connection maximum to 1 for testing. If you check the latest main repository, take a look at the lib-core crates. When we create the SQLx client, there's a cfg test that sets the maximum to 1. It's not the most elegant solution, but it works and has no impact on production.
@jimitsoni18
@jimitsoni18 7 ай бұрын
@@JeremyChone hello Jeremy, thanks for replying so quickly, you are a blessing, truly
@jimitsoni18
@jimitsoni18 7 ай бұрын
Hello Jeremy, I am facing I am trying to follow this tutorial and I am doing everything as explained, but I am not getting the tracing logs on my stdout, can you please tell me why
@JeremyChone
@JeremyChone 7 ай бұрын
Make sure that in your `.cargo/config.toml` you have the right crate names in the RUST_LOG environment variable. See: github.com/rust10x/rust-web-app/blob/main/.cargo/config.toml
@jimitsoni18
@jimitsoni18 7 ай бұрын
@@JeremyChone thank you!
@johnwilliams7999
@johnwilliams7999 11 ай бұрын
i havent watched this yet but i struggle with axum with the in memory database and setting up a real database stuff. Hopefully you cover that in the videeo
@JeremyChone
@JeremyChone 11 ай бұрын
Oh, this video features a real Model layer that interacts with PostgreSQL. The Rust Axum Full Course serves as a mock store designed to teach the mechanics of Axum. So, I believe this video should answer your question. Please let me know if it doesn't.
@ronilbiswas
@ronilbiswas 4 ай бұрын
Where can I find the starter code for this session? (Refactored code from previous video: axum full course)
@JeremyChone
@JeremyChone 4 ай бұрын
It's in the github as ". initial" It's mostly the Rust Axum Full course a little bit preped .
@ronilbiswas
@ronilbiswas 4 ай бұрын
@@JeremyChone thank you
@lame_lexem
@lame_lexem 10 ай бұрын
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.
@JeremyChone
@JeremyChone 10 ай бұрын
Ok, this is a great question. I plan to create a page on rust10x.com and/or a video to discuss the pros and cons of each approach and explain why we prefer the SQL (e.g., SQL builder) route. In the meantime, here are a few points: - Firstly, the Model layer code is designed to decouple implementation details from the rest of the application code. - Therefore, while the Model layer can utilize an ORM (e.g., Diesel) or a more SQL-centric approach (e.g., sqlx / SQLB), the remainder of the app's code shouldn't need to be aware of these specifics. - We have extensive experience with ORM, going back to our time working with Java, using Hibernate and familiarizing ourselves with JPA in general. - However, even during our Java days, we gravitated towards a more SQL/SQLBuilder approach, akin to JOOQ. - ORMs can simplify the initial stages but may become overly complex as development progresses. - They tend to lock language data structures (like Java classes or Rust Structs) to their respective tables, requiring meticulous attention to ensure perfect alignment between the two. - Although this approach might seem attractive initially, we found that it does not scale well for larger applications (with 200k to 500k LOC). - The intertwining of language types and database table structures and relationships can become a source of complications, causing issues for both elements. - Taking the time to understand SQL deeply and learning how to effectively query data for specific functionalities greatly simplified our system, despite the additional SQL knowledge it required. - We reduced many instances of O(n²) and O(n) complexity to O(1). This improvement was not so much a reflection on the flaws of ORMs but a benefit of abandoning a one-size-fits-all approach, enabling us to optimize our query and data assembly processes. - Indeed, working with raw SQL can also have its own set of problems; it is error-prone and can be tedious, especially when ensuring the use of prepared statements and maintaining track of argument IDs. Moreover, the necessity for order in SQL does not lend itself to composability. - This is where SQL builders, akin to knex.js in Node.js and JOOQ in Java, come into play, offering great composability benefits while staying true to the relational model. - It's crucial to note that the design blueprints at rust10x (encompassing rust-web-app, this one, and the rust desktop app - formerly known as AwesomeApp) are built with a model layer design. This means the choices made here are layer implementation details and should not affect the rest of the code base. - It is a fundamental rule that anyone wishing to read or write to any store should do so through the model layer. - Therefore, developers can utilize this blueprint and employ tools like SeaORM or Diesel without encountering many hiccups. So, in short, I believe that staying closer to the respective stores, be it a database, S3, or Redis, offers better scalability. Moreover, a good scalable design, irrespective of the approach chosen, involves establishing the right application abstraction layer (e.g., the model layer) from the outset. I hope I have somewhat answered your question. I plan to delve deeper into this subject in the future. It's important to note that the blueprint supports both approaches. I personally prefer the one that I believe scales better for our style, but other styles are completely fine too.
@junwu22
@junwu22 10 ай бұрын
​@@JeremyChone Thank you very much for your time by giving so much detail and examples!
@abnerlee1910
@abnerlee1910 7 ай бұрын
Hello, may I ask how to design if I want to transfer database transaction objects from the logic layer to the model layer?
@JeremyChone
@JeremyChone 7 ай бұрын
Hi, what do you mean by logic layer ?
@abnerlee1910
@abnerlee1910 7 ай бұрын
@@JeremyChone I hope that the database transaction can be started when the model method is called in the business logic code. The logic layer here refers to the place where the business logic code is written
@abnerlee1910
@abnerlee1910 7 ай бұрын
@@JeremyChone Assuming that I have an interface for placing orders, which involves modifying multiple tables (order, order_detail, user, wallet, points, goods, etc.), I need to initiate database transactions to ensure data consistency. Currently, the framework does not involve database transactions. I hope to see this section as soon as possible. Thank you very much.
@JeremyChone
@JeremyChone 7 ай бұрын
I am currently undertaking a major upgrade for seamless transaction support. Essentially, the design remains the same, but now you use `mm.dbx()` to execute SQLx commands. Then, you can initiate a connection with `mm.dbx().begin_txn()`, and any subsequent use of `mm.dbx()` for SQL will be within this transaction. This should be quite exciting. Keep an eye on the repository; a big update is coming soon. I'll try to make a video about it. For more information, feel free to join the Discord:
@abnerlee1910
@abnerlee1910 7 ай бұрын
@@JeremyChone Wow, I'm really looking forward to it
@stevenkovacs3113
@stevenkovacs3113 Ай бұрын
Which font do you use?
@JeremyChone
@JeremyChone Ай бұрын
I think “menlo” for vscode, and “lato” for video text.
@zrustacean
@zrustacean 8 ай бұрын
What's extension that you used to generate code?
@JeremyChone
@JeremyChone 8 ай бұрын
just vscode snippets. Here are some: rust10x.com/vscode
@JeremyChone
@JeremyChone 7 ай бұрын
Btw, I finally took some time to create the Rust10x VSCode Extension and a webpage with information about my VSCode setup. Everything can be found here: rust10x.com/vscode
@phinguyen7381
@phinguyen7381 4 ай бұрын
hey sir, can u share the rust snippets for vscode, thanks
@JeremyChone
@JeremyChone 4 ай бұрын
Here is the little extension I made. rust10x.com/vscode If you go to the extension install page, you can click on respository to see the github source.
@phinguyen7381
@phinguyen7381 4 ай бұрын
@@JeremyChone thank you, sir
@ivandardi
@ivandardi 11 ай бұрын
Do you earn any money from these courses or is this truly altruistic?
@JeremyChone
@JeremyChone 11 ай бұрын
Good question. My aim is to strike a balance by offering high-quality content for free on KZfaq, while also planning to build a unique learning experience on awesomeapp.dev for production coding (currently just a very simple static website). For now, I have a Patreon page (patreon.com/jeremychone), where any_help == big_help. I've been running my business focused on building Big Apps with Small Teams for some time, and I'm taking a shot at pivoting to share this expertise with a wider audience, rather than just a select group of clients. Only time will tell if this approach will be successful, but if it is, more happy coding!
@irlshrek
@irlshrek 11 ай бұрын
in my opinion, he should try to make money so that we can get more of these videos!
@surajmandal_567
@surajmandal_567 10 ай бұрын
Why rust is so difficult 😢.
@ryz177
@ryz177 9 ай бұрын
This is awesome! I hope you can do another one of these but instead for a popular web app cloned in Axum like Reddit, Spotify, KZfaq, or Twitter! Thanks for these lessons!
@JeremyChone
@JeremyChone 9 ай бұрын
Ho, interesting, building a Spotify or Reddit clone you mean? That could be interesting once I finished the blueprint. Still many episodes to come to make it full production.
@ryz177
@ryz177 9 ай бұрын
@@JeremyChone Yes! It's what React/ Next usually have as an advantage, as there are lots of tutorials like that which interest people. This might be a chance to bring in more people to the Rust community and maybe make the contribution to this space a lot faster than ever. Again, thanks for these kinds of tutorials, its badass great!
@JeremyChone
@JeremyChone 9 ай бұрын
​@@ryz177 Cool, I've considered creating new upcoming startup ideas, but just cloning existing apps could be great. The Rust10x web-app will be well-structured for that purpose. Thanks for the feedback!
@Middlew
@Middlew 25 күн бұрын
Hi great course so far, I am doing what you are doing in the course, however when I run: $ cargo test model::task::tests at 1:18:15 when my code refuses to run all the tests at the same time (both manually and cargo-watch) unless I restrict the number connections to max_connections(1) in new_db_pool() in store/mod dot rs. If I dont there is a very high likehood (>95 percent) that one of the tests fails due to Error: Sqlx(PoolTimedOut). The order of the tests does not matter (random fails each time, sometimes two fail) with the console just handing until it gives the error. No error shows up when I run them after each other, not in vscode or calling them seperately line by line. Any ideas what could be wrong? Removing #[serial] from each test did not work, and instead makes it so the code gives other errors. I have tried changing back version from the latest to the version in the video but no luck.
@Middlew
@Middlew 25 күн бұрын
Found you answer in these comments. Thanks anyways. Good to know it wasn't on my end and I figured out the solution on my own 😅
@JeremyChone
@JeremyChone 24 күн бұрын
Yes, this was something introduced with Sqlx 0.7. I set the max connection to 1 during testing to make it work. I think it's a decent workaround. Not sure why Sqlx hasn't fixed this issue, but it likely only happens in test mode.
Python for Beginners - Learn Python in 1 Hour
1:00:06
Programming with Mosh
Рет қаралды 17 МЛН
Double Stacked Pizza @Lionfield @ChefRush
00:33
albert_cancook
Рет қаралды 103 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 12 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 8 МЛН
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 79 МЛН
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 102 М.
Why Rust is NOT a Passing Fad...
8:54
Travis Media
Рет қаралды 32 М.
Goodbye javascript (for now)
14:57
Web Dev Cody
Рет қаралды 68 М.
SQLx is my favorite PostgreSQL driver to use with Rust.
9:47
Dreams of Code
Рет қаралды 50 М.
3 ways to reduce the size of your docker images
17:20
Raghav Dua
Рет қаралды 4,3 М.
The Star Language that will outshine Rust? Gleam
10:33
Code to the Moon
Рет қаралды 28 М.
Rust Error Handling - Best Practices
21:33
Jeremy Chone
Рет қаралды 17 М.
So, you want to be a programmer?
20:43
ForrestKnight
Рет қаралды 234 М.
The mind behind Linux | Linus Torvalds | TED
21:31
TED
Рет қаралды 6 МЛН
Это Xiaomi Su7 Max 🤯 #xiaomi #su7max
1:01
Tynalieff Shorts
Рет қаралды 2,1 МЛН
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 64 МЛН
АЙФОН 20 С ФУНКЦИЕЙ ВИДЕНИЯ ОГНЯ
0:59
КиноХост
Рет қаралды 1,2 МЛН
Rate This Smartphone Cooler Set-up ⭐
0:10
Shakeuptech
Рет қаралды 6 МЛН
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
ALSER kz
Рет қаралды 337 М.