4 ms·
The author talks about http servers. So I will throw a question here. I am a gopher that wanted to try rust, and I looked into http servers in rust, and it loo
by shp0ngle 4y ago
The author talks about http servers. So I will throw a question here.
I am a gopher that wanted to try rust, and I looked into http servers in rust, and it looks like there is like 10 different http servers, and each of them carries with them something that is called “async runtime”, and there are different async runtimes, and you cannot (or can?) use them together, and I realized async rust is not yet finished (or it is?), and I got kind of lost.
What http servers people used? Do the asynch runtimes matter? If I want to “just” build a http server, do I need to study different async runtimes?
- Klonoar 4y agoPretty much all the http servers of worth, short of tide, just use Tokio at this point. For the most part, you really only need to care about Tokio. async-rs is used by some libraries, but it's relatively small in comparison - and many now go to lengths to just support both. There are other runtimes you could tinker with, but really: just use Tokio. The "easiest" web server/framework to get started with in 2023 is, in my opinion, Axum. It's from the same people who work on Tokio and it does make it somewhat straightforward to dive into as a result. I have a few actix-web servers in production as well, and it's a fine framework - hard to say where the mindshare falls on it these days. Rocket is a very nice web framework but effectively has a bus factor of 1 at this point and it's started to show. People coming from e.g Rails may appreciate it though. Don't use warp (IMO) because http routing is not rocket science and doesn't need the amount of magic it tries to bolt on. Have fun.
- TheDong 4y agoI mean, there's only one http server people actually use, which is hyper. Just like in go where everyone uses net/http, even though fasthttp and so on exist and everyone just ignores them. Just like in go, there's also a lot of web frameworks built on top of it (like all the ones listed here for go: https://github.com/mingrammer/go-web-framework-stars https://github.com/mingrammer/go-web-framework-stars) Just like in go, you can choose not to use any if you want and use hyper directly, or use one that is a quite thin layer on top of hyper like axum. In terms of async runtimes, just pick tokio and get on with your life. It's the default choice, so picking it is the simplest option.
- imwithstoopid 4y agoYes, you must deal with async It's not that big of a deal though Axum is popular but feels too low level to me, but some nice porcelain APIs might eventually be put on top of it
- antonvs 4y agoWhat feels higher level to you than Axum? I picked Axum because it seemed higher level than the alternatives I looked at, including actix and warp.
- satvikpendem 4y agoThey're likely talking about Rocket which is higher level than Axum or Actix Web, but it's recommended not to use it as it's not as actively maintained, as well as some other issues. For a Rails-like experience, Nails [0] is one I've seen, although I don't know the status of it as no one seems to talk about it as much as Axum and Actix Web. [0] https://rust-on-nails.com/ https://rust-on-nails.com/
- linhns 4y agoI think axum is pretty decent tbh, considering it's part of Tokio and will get better support than most servers out there
- Animats 4y agoIt's possible to avoid async contamination in Rust. Game-type programs generally don't use it, because they're compute-bound. The use case for async is a huge number of mostly inactive network connections.
- earthling8118 4y agoWhat makes it feel low level to you? Axum has been my favorite way to do HTTP servers for some time. Especially where it is now, everything feels expressive, and I can do whatever I need to. If you're just doing basic stuff it makes it easy and if you're going beyond that it makes it possible. There are a few parts of the learning curve that come up but the official examples showcase it all beautifully and the community is very responsive if you ask for help.
- culi 4y ago> async rust is not yet finished (or it is?) https://areweasyncyet.rs/ https://areweasyncyet.rs/ see also: https://www.arewewebyet.org/ https://www.arewewebyet.org/
- ozten 4y agoAsync is really painful and a "not finished yet" thing. However, in practice, if you use Tokio you should be fine. And usually this decision will be made for you with the framework you pick. My #1 tip is to decide on exactly what your use case is, then use cargo and look at the recent number of downloads and go with the most popular framework. Doing this for several tags (http, server, framework) is required for categories that are noisy or not tagged well. Example: Are you writing a web service API, a web server that has server-side templates, a client-side SPA app, or a server-less function? Usually you will see they are all aligning on the same stack tokio, serde, etc but this is definitely something to be aware of. It is critical that an application uses the same version of dependencies for cross cutting concerns.
- pnathan 4y agoMy (older) code uses nickel, a sync web server that is, sadly, out of date. I'll be migrating from that to one of: * https://github.com/tomaka/rouille https://github.com/tomaka/rouille * https://github.com/tiny-http/tiny-http https://github.com/tiny-http/tiny-http