5 ms·
Choosing the Right Rust Web Framework: An Overview
- milliams 3y ago[flagged]
- deleted 3y ago[deleted]
- synergy20 3y agoA critical question first: why do I ever need Rust for web development? Typically a critical question at HN will get downvotes because it is not encouraging or constructive or whatever, but that's OK as I really want to know the answer here. I understand Rust is cool for system programming, but I don't feel Rust is good for _everything_ Assuming you have some cash to make web related products, are you going to use Rust web framework at all? I know I won't.
- bryanlarsen 3y agoSurprised not to see this answer yet: To put a web interface on a rust program. Suppose you have a program that does something very much non web related but well suited for rust, like embedded, or heavy CPU calculations, high speed control, etc. And suppose you want to add a UI or API or RPC or Prometheus metrics or monitoring or etc to a program, HTTP is often a convenient way to do it.
- deleted 3y ago[deleted]
- bigmanwalter 3y agoRust is good for writing performant code, incorporates a lot of the latest programming language research, and gives great error messages. You don't need it. But if you prefer using it, it's nice to have a web development framework.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- nonethewiser 3y agoI asked the same question and imagined a snarky response like "Well whenever you want a fast, memory-safe api." But seriously, I don't know. It seems like it trades development speed for things that just aren't problems. I think the database would be where most performance issues would surface, not the api server. I'm curious how others will answer your question though because I'm not really sure.
- hu3 3y agoEven when performance is important, C# and Java are top performers: https://www.techempower.com/benchmarks/#section=data-r21 https://www.techempower.com/benchmarks/#section=data-r21 Heck people use some incantations of Java for High Frequency Trading even. Besides, web application bottleneck is usually the database.
- riquito 3y agoWhat you write and what's in the results you linked tells quite a different story (composite scores)
- hu3 3y agoAre we looking at the same thing? https://i.imgur.com/blA0Oi4.png https://i.imgur.com/blA0Oi4.png
- riquito 3y agoPerhaps I misinterpreted what you said as "Even when performance is important, C# and Java are top performers". I read it as "they are the top performers", and there are faster rust frameworks in that benchmark, but perhaps you meant "Among the top performers there are non-rust language which are good options without having to use rust"
- hu3 3y agoInterestingly, the fastest in that benchmark, above Rust, C++, Java and C# is... JavaScript. Goes to show how benchmark minigames are broken and also that most languages are good enough.
- camdenreslink 3y agoGood performance, nice type system to model business logic, easy to deploy a single executable. Low resource usage can be more affordable at a certain scale. A lot of concurrency models that you can choose from. Other languages have some of those features, but not necessarily all.
- bobbylarrybobby 3y agoYou don't. But despite its reputation, rust is an incredibly pleasant language to work in and so if you're already using it, it would naturally be what you reach for for your next project.
- pyr0hu 3y agoNot web development per se, but I had to write an FFI connector in Rust (because of some multiarch shenanigans) and I want to create an API to manage the connector remotely - it's a proxy for card readers - so I can manage the gates, the config, etc. through a HTTP api as the rust proxy is at the moment is just a daemon.
- infamouscow 3y agoMost of the Rust folks aren't interested in articulated discussion about trade offs, they're zealots making a moral argument and view themselves with a sense of divine superiority parallel to the Christian crusades. This is made exceedingly clear if you ask for specific examples of when Rust shouldn't be your first choice or when Rust is second-fiddle to more optimal solutions.
- fleventynine 3y agoMost of us don't spend our time arguing online; we're busy using the language in domains where it's clearly the best choice: embedded and systems software where memory safety and a tight memory footprint are more important than productivity for new developers. Once you have a few years experience under your belt, it's natural to want to use the language in other domains like large web applications, even though it's only a reasonable choice because you already spent the effort to learn the language.
- bowsamic 3y ago> Most of us don't spend our time arguing online; we're busy using the language in domains where it's clearly the best choice That seems like a highly unrealistic claim to me.
- fleventynine 3y agoThe fact that there are some domains where Rust is clearly the best choice? Or that there are plenty of corporate Rust users who don't make their language choice part of their identity?
- bowsamic 3y agoThe latter
- gv83 3y agoyou forgot the part about parroting arguments around "soundness", "realiability", "correctness", "easier to reason about" and "refactorings" for the 2-internal-users-only 2 models crud, completely ignoring the notion of non-functional requirements. they already killed scala, let's see how much time they need to kill rust
- commandar 3y agoI could see potential value in the semi-embedded device space. 3D printers are an area where I've been kind of expecting Rust to eventually take hold. Printers require fairly performant systems level firmware but the trend is toward users interacting with them pretty much entirely via webui. Right now, Klipper is one of the more popular 3DP firmwares. It's a mishmash of Python and C at the firmware layer with Moonraker (Python) sitting at the API layer and then some soft of JS-based UI like Mainsail or Fluidd sitting on top. I can see very real appeal to squashing the firmware and API layers down into a more coherent stack. Having a batteries included web framework would be helpful there.
- devit 3y agoRust is the best programming language, so the question is more why you wouldn't use it. And the answer is you wouldn't use it if there's a library or existing codebase in another language that is much better than the Rust equivalent, and the program is short enough that it's simpler to directly use that language rather than writing a binding or RPC interface. Or if you need the software to be written by someone who doesn't know Rust and doesn't want to learn (but in that case, they might not be able to write a correct program in any language, so this strategy is probably best reserved when a program that only works properly sometimes is acceptable).
- Thaxll 3y agoComments like that make people not want to use Rust. As good as Rust is, there is no such thing as "best" language.
- adamnemecek 3y agoRust is as close to "best" as you can get.
- konart 3y agoThere is no such thing as "best" unless the problem and restrictions it creates are specified.
- synergy20 3y agowhat about golang for web developments then, it's arguably much easier to use, single binary, and memory safe.
- adamnemecek 3y agoEasier maybe, definitely not more pleasant, at least for me.
- jokethrowaway 3y agoI agree in principle, on the other side... I can't think of any other language with the combination of safety guarantees, high level language and a community producing very cool crates. Rust dethroned Haskell for me, and I'm excited my favourite language is actually an approachable one for once. I think everybody can learn Rust (unlike Haskell, I gave up on trying to teach people), you literally just follow the borrow checker until it works.
- freedomben 3y agoDisclaimer: I currently use Phoenix for everything web, and I've never written any serious rust although I want to because it intrigues me. I would imagine it's one of those "I already know Rust really well and I want to write a web app." Phoenix (like Rails back in the day) is one of those frameworks that makes it worth learning a new language, but those are the only two I know. The rest of the frameworks I've seen compelling are mostly to allow somebody to stay in the language/ecosystem that they're most confident/familiar with.
- indy 3y ago1. Efficient use of server hardware. I'm cheap and use a low-spec server 2. Code re-use between client and server. I have some application logic that can run on the server and on the client via WASM compilation
- masklinn 3y agoThe efficiency is also nice for paas/faas scenarios.
- dlisboa 3y agoOne reason would be reliability. Almost all of the errors on the application I work on are nil references or errors that were expected, but just weren't handled. Rust forces you to handle those at compile time, ending with a better all around software. There are other languages that achieve the same, I'm just comparing Rust to the usual suspects for web-dev (JavaScript, Ruby, Python, PHP, etc).
- gv83 3y agobetter for who? if you're building The Wrong Thing it doesn't matter. also, "soundness" and "reliability" are not non-functional requirements FOR EVERYTHING
- jokethrowaway 3y agoI choose Rust for web development, the oldest running product I have is ~2 years old at this point. Prototyping is slower but maintenance is faster. It's a trade-off. I have a bunch of products and every once and then something needs fixing. When it's one of my node.js or python projects it's usually a bath of blood and I'm never confident I changed the right things. With Rust I get a type error until everything is plugged in correctly - the only mistakes I get are logical ones. TypeScript kind of gives you a similar experience but it has more escape hatches. If you want to close all the exceptions and make everything type safe it will take you a similar amount of time as writing Rust code. The end result is that when I see a TS codebase I can't trust it: I might have written some unknown / any and there is a massive gap in types. This negates any benefits I get from type safety. In Rust this is not possible, as long as you're using safe dependencies (which you most likely are if you're writing a web service in Axum).
- DarkNova6 3y agoRust‘s Killer Feature is excellent support for Webassembly. No GC, no problem.
- nelsonic 3y ago"I recommend you to go with Actix or Axum" ... for what use case? Choice is good. But too many options creates decision fatigue. Really wish the creators/maintainers of Rust would adopt one Web framework and standardise on it so the Rust-curious could have an easier entry point. That's what I really like about the Elixir ecosystem; Phoenix is the automatic no-brainer choice. Just crack on with building your idea.
- hu3 3y ago> That's what I really like about the Elixir ecosystem; Phoenix is the automatic no-brainer choice. Just crack on with building your idea. Yes cohesion is great! For C# we have ASP.NET dominance (and Java has Spring?). At the end of the day our job is to deliver value.
- saila 3y agoI've been learning .NET recently and there are several choices for building a webapp, such as MVC, Razor pages, and Blazor (further split into server vs web assembly). MVC uses Razor views, Razor pages use Razor pages, and Blazor uses Razor components. MVC without the V is apparently the recommended way to create APIs. I spent quite a bit of time trying to understand the distinction between these options and when you would choose one over the other, and I would have to disagree that it's a no-brainer choice. Perhaps if you've been in the .NET ecosystem for years and have followed the changes but definitely not if you're new to it.
- hu3 3y agoFor something that was released 21 years ago, it's not that complicated: - Razor pages, views and components use the same templating language. - If you want MVC you can use Razor views and Components to render things from your Controller. - If you want something simpler like a website, you can use Razor Pages and Components. - Blazor is the new shinny thing. It still uses the same Razor templating language but targets for webassembly or Phoenix-style LiveView. And for APIs, it's just the ordinary Controller -> Action -> JSON as every other framework.
- jstx1 3y agoWhich one is getting actual adoption? What framework are AWS using for their Rust services? Any other big companies?
- Dowwie 3y agoordered by daily download popularity: - https://crates.io/crates/axum https://crates.io/crates/axum - https://crates.io/crates/actix-web https://crates.io/crates/actix-web - https://crates.io/crates/warp https://crates.io/crates/warp - https://crates.io/crates/rocket https://crates.io/crates/rocket - https://crates.io/crates/poem https://crates.io/crates/poem these numbers pale in comparison to download stats of web frameworks in other languages (ie Flask, Django), but they have grown significantly in the last 3 years my guess is that Axum is what AWS is using internally, else the grpc counterpart server called Tonic
- ARandomerDude 3y agoUpvoted because Rust. I don't use Rust but one day I might outsmart the borrow checker.
- freedomben 3y agoA bit of a side question. I'm a longtime developer considering diving into rust a bit. I really like the style shown in the examples in TFA. Is the style shown in the examples pretty typical in the ecosystem? Is there tooling that will achieve those results?
- grayrest 3y agoAs far as I can tell the formatting is standard `rustfmt`. Ships with the compiler.
- szundi 3y agoYou don’t have to learn Node stuff/Java/Spring/PHP/ASP.NETC# stuff if you already know some Rust. Or you’re working at one of the biggest project and need all the performance. Not sure it has ROI vs Java even then. Anyone with experience from Rust vs something else firsthand?
- deleted 3y ago[deleted]
- mgomez 3y agoI've spent the last several weeks porting a backend I had written in Go over to Rust (using Axum) and so far so good. But I don't know if I can call things in the Rust world like Axum/Actix/etc. "frameworks" anymore considering all the time I've had to spend researching/vetting crates to get the same functionality that comes out of the box in Spring/ASP.net/Django/etc. Take handling datetimes for example. Do I use time or chrono? The initial developer/maintainer of chrono left[1] and for the longest time the crate was unmaintained while a CVE remained open[2] until a new maintainer finally came along and addressed it (I think?). All right, so, time it is then... but it uses its own custom format specifiers[3] that I had to get used to coming from the more familiar strftime used by other languages. Or how about input/form validation. One of the most popular crates for that, validator, had its maintainer admit that they don't even use it themselves?[4] Of course I can already hear people yelling at me, "well, why don't you contribute then?!", and I certainly would love to if I could! But I have to finish what's in front of me first. That being said, I still very much enjoy using Rust. Maybe less so for web-related projects. I just have to stay on an even keel despite the growing hype. [1]: https://old.reddit.com/r/rust/comments/qamgyh/is_the_chrono_crate_unmaintained/hh6rh6y/ https://old.reddit.com/r/rust/comments/qamgyh/is_the_chrono_... [2]: https://github.com/chronotope/chrono/issues/602 https://github.com/chronotope/chrono/issues/602 [3]: https://time-rs.github.io/book/api/format-description.html#version-2 https://time-rs.github.io/book/api/format-description.html#v... [4]: https://github.com/Keats/validator/issues/201 https://github.com/Keats/validator/issues/201
- tharmas 3y agoNot sure if this is of any use: https://github.com/leptos-rs/leptos https://github.com/leptos-rs/leptos https://docs.rs/leptos_axum/latest/leptos_axum/ https://docs.rs/leptos_axum/latest/leptos_axum/
- masklinn 3y ago> But I don't know if I can call things in the Rust world like Axum/Actix/etc. "frameworks" anymore A "framework" is a thing which calls your code rather than the other way around. You're confusing framework and "full stack" framework. Actix or Axum are web frameworks in the same sense Flask or Sinatra are web frameworks: they deal with the HTTP lifecycle, and call your code when certain conditions are met (usually around routing).
- spiffytech 3y agoGenuine question: why do people consider Axum's developer experience "great"? I've seen people say that several times, but the reason never seems clear to me. Is it something that only starts to pay off in more complicated projects? Or is there some angle I'm missing? Compared to other frameworks I've used (Rocket, or frameworks in other languages), I've found Axum to be challenging to get up-and-running with. It's hard to figure things out from the docs. Basic features require 3rd-party packages. I have to guess my way out of compile errors because the error message & their types are unintelligible. And Axum transparently passing on the underlying Tower (and Tokio?) concepts piles on how much knowledge is required to use the framework.
- Spartan-S63 3y agoI agree. Axum feels really raw and I understand some folks like it, but it's more of a microframework in that regard than something like Rails, Django, etc. To me, Rocket has always had the best ergonomics to get going and Actix with macros is a close second.
- wvh 3y agoThese objective ecosystem overview articles are pretty interesting to get a good idea of what options are available and what their respective state and rate of adoption is. Especially as a senior developer or consultant, it pays dividends to keep up to date and be able to give the right advice when new projects are started. Choosing the wrong language, ecosystem or paradigm is in my experience the main cause of project failure, being way over time or just general frustration all around. If it's your job to make those technology decisions, you better stay informed lest you paint the whole project into a corner, if not immediately, then a few years down the line.
- capableweb 3y ago> Choosing the wrong language, ecosystem or paradigm is in my experience the main cause of project failure, being way over time or just general frustration all around. That's interesting, in my experience doing consultancy in bunch of small to mid sized companies, failure seems to most of the time come from anything but technology and much more around people, groups, relationships between those people and groups and how work is organized on a weekly basis.