DEV Community

Discussion on: State of Rust Web Frameworks (Server, DB)

Collapse
 
ghost profile image
Ghost • Edited

I'm not an expert but my take on those:

With stability, performance, features, and learning curve in mind which is best?

I've worked a bit with actix-web for a while, nothing big, but so far seems very stable to me; I think that in this moment in the ecosystem the lacking "stability" is more about that because a lot is new, is subject to changes, so you may have to updat your code with each version, for more long term projects now I would recomend actix-web or plain Hyper; Rocket has been around for a while but still uses nightly and soon should adopt async so I think the codebases may have to change soon. So far Rust in general has never done anything unexpected and doesn't make easy to cut corners. As you may see, a lot of packages advertize now #![forbid(unsafe_code)] which is a big plus; feature wise is not as complete as say Django, but is getting there, and in general I see more of a "Flask" aproach, not sure any framework is interested in become a "Django", everyone seems focused in making everything as modular as possible.

About the learning curve is tough, it took me a long time to grasp Django (I know I mention Django a lot, but I've worked with it the most), is so big and does so much that is difficult to understand the whole picture, a lot to do your first little project; with, for example Hyper, you build bottom up, so you get the whole picture easier, also is lower level so you instantly understand the whole thing and how simple it is and how every piece fits together. You check docs.rs/hyper/0.13.3/hyper/server/... and even not knowing Rust you can get what is doing it and you build from there.

Are any worth adopting yet? Why (not)?

Absolutely yes, I don't think actix-web will get another big change, the API is already pretty stable, in Rust the version numbering is a bit more "organized" than in other PL, so hit the 1.0 means something and Actix is already close to v3, Tide devs have said it, they have the line "not ready for production" in their page not because the code may fail but because they may do big changes with each version, so you have to adapt your code accordingly so is more of an "operation instability" not that the code is not well baked; Hyper is also being used by a lot of other projects (is a library not a framework) so they are careful to not break things. I've learned a lot this lasts months with Rust, things that I avoided and even feared when using Django are clear to me now.

Are they only usable for niche projects? What use cases?

I don't have enough experience to tackle this one but I don't see why not. Of course there is the natural difficulties of a smaller user base, is harder to hire Rust devs than PHP, JS or Python. You have less people around that can help you, etc. But is a matter of time, I'm sure that Rust is gonna get bigger and better, fast, we haven't even stretch its legs with webassembly yet, most wasm frameworks are using old models, but in time I think you'll have all the tools to make your whole stack in Rust, from the DB to the browser.

Collapse
 
mremanuel profile image
Emanuel Lindström

Thanks for sharing.
I also have experience with Django and agree with it being kind of a monolith. It does a lot and is hard to grasp at first. But when you learn it, it's super nice to work with.
I just finished my first hello world in rust and I'm thinking of diving in the deep end and building a web app. Can you recommend a good approach? I've looked at Rocket and actix-web and I kinda find myself looking for something similar to django. Especially the django ORM is super nice.
Although, I wouldn't mind going a bit lower in abstraction now that I'm getting in to rust. To "do it right" so to speak. My plan is to build a simple, full stack web app. A portfolio perhaps where I can showcase projects, build a rust game, etc. Maybe play around with logins and user authentication.
Can you point me in the right direction in what kind of stack I could use? I don't mind if it's a single framework or one for frontend and one for backend. Thanks!

Collapse
 
ghost profile image
Ghost

I would recommend an approach similar than what I would have liked to do with Python, to take a look at Flask before Django, if you get directly into Django, after a while, with Django, I felt more like a "configurer" than a programmer, is like filling the little blanks Django left for you.

I would start taking a look at Hyper, maybe do a hello world with it, after that depends on your goal, is to explore or to build something you have already in mind. For the first I find really interesting what is being done with async-std>http-types>async-h1>tide and just understand whar role play each of those parts have gave me, in a week, more understanding of the whole thing than years of Django; if you already have a project in mind and is kinda complex i.e. you want good middleware support, cookie based auth already done, TSL, websockets, etc. I'll go for Actix-web. It doesn't come with ORM like Django but is much more feature rich than other (not sure about Rocket, I've never used and barely look at it). The database stuff is decoupled entirely from the rest so the choice of web stack doesn't affect your db availability.

I bet you'll get a lot just at looking the hyper server example. Notice that Hyper is not a framework is a library, but you'll realize than is not so different, and even if you go for Actix-web, a look at Hyper will make the whole actix-web structure, clearer.

That is what I've gather as a noob in the whole thing. And if you came from Django, Askama will feel like home with templating, in fact is based in the syntax of Jinja, so with some minor adjustments, you could even reuse your Django templates, and as is completely decoupled with the rest (DB and http server: actix-web, tide, hyper, etc.) you can mix and match.

Collapse
 
readredready profile image
Charles Gibson

Wow, thanks for your insight!

Besides Rocket and Tide having LTS, it seems like there is plenty of good options. If you forced me to start today I would probably just get into Actix-web to be on the safe side. But since I have my hands full at the moment, so I get to wait to see how Tide develops. The async-std seems like an attempt to put out a Rust standard standard and its developed by the people who made Tokio, so it should be mature soon and stable even in the mean time. It sounds tidy too!

I also will get to see how SQLx matures since I prefer writing in SQL.

I think anyone who reads your input will be pretty tuned into what's going on with Rust web frameworks today.