7 ms·
Rocket, Rust Web Framework, v0.2: Managed State and More
- moosingin3space 10y agoI'm very excited about this. I've been looking for a good open-source statically-typed web stack for a long time, and the Rust community delivered. Now, when this works on stable, it'll be awesome!
- rshm 10y agoStill without ssl. Nice to see lots of stars and forks.
- nilved 10y agoSSL is really not the responsibility of the web framework.
- k__ 10y agoAre reverse proxies always the way to go?
- tracker1 10y agoIn the age of "microservices" it seems to be the direction. Also, in any HA deployment, would generally be the case anyway.
- stefs 10y agoi always just use nginx and don't see any downsides.
- deleted 10y ago[deleted]
- dozzie 10y agoNo. Usually web application would be exposed through FastCGI or similar protocol. Insisting that either your tiny web application that can do next to nothing is the thing that owns 80/tcp (and/or 443/tcp) or runs behind a HTTP proxy is stupid. Proxying HTTP requests properly is harder than it sounds, which is surprising every now and then and thus is easy to screw up (what happens to Host: header? who is the TCP client? is it HTTP or HTTPs?), and your tiny web application, as I've called it, is not the only thing I want to host on the machine.
- k__ 10y agoInteresting. I only met FastCGI in PHP. All NodeJS apps I saw used HTTP. Is there any benefit of doing it that way? How does it work with WebSockets?
- dozzie 10y ago> I only met FastCGI in PHP. All NodeJS apps I saw used HTTP. And I met FastCGI in Python, Perl, Ruby, and Erlang (though I haven't used the last one yet). Oh, and uWSGI can expose anything it runs through FastCGI. My personal opinion is that web crowd (most of JavaScript programmers fall in here) just doesn't want to learn from anybody else. > Is there any benefit of doing it that way? Compared to running the tiny web application on 80/tcp? Sure: I can run more than one and I don't need root privileges for the application. Compared to running the application behind a reverse proxy? Ditto: it's virtually impossible to get the setup wrong, so it's easier in the long run. > How does it work with WebSockets? No idea. I don't develop web applications.
- k__ 10y agoI just read that WebSockets aren't supported by FastCGI, so I guess this is the reason for all the reverse proxying in Node-land, hehe
- krzyk 10y ago> My personal opinion is that web crowd (most of JavaScript programmers fall in here) just doesn't want to learn from anybody else. Where would you put Java programmers? I haven't seen FastCGI there. > No idea. I don't develop web applications. So why do you talk about FastCGI? It is strictly for web stuff.
- IshKebab 10y agoIt includes a web server.
- bigdubs 10y agoThere are deployments where the traffic from the LB => app instances needs to be encrypted, so it would be the requirement of the server. Source; I build secure financial services software day to day.
- oregontechninja 10y agoI've been using the framework to practice rust and it's really pleasant. I would compare this to "flask" from Python. I've got an experimental static site cms (for my clients eventually) where the administration back end is a dynamic library so I can update the back-end without stopping the serving of the website to the public. Really fun learning experiment and crazy fast server overall. For now, I still use Go, but Rust's meta features are so much more advanced that I'm working on switching.
- eknkc 10y agoJust curious, I really want to like Rust but take a look at the State API documentation for managed state feature: https://api.rocket.rs/rocket/struct.State.html https://api.rocket.rs/rocket/struct.State.html (screenshot: http://c.ekin.io/3c2q112x1p0y http://c.ekin.io/3c2q112x1p0y) Is this readable to Rust people? I mean, can you look at this and say, "ah ok, I'm gonna call this and that then I'll have the state" directly? I'm lost but I have zero Rust knowledge so this is a sincere question, does this mess make sense when you get into it?
- wrs 10y agoWith a couple of weeks of Rust experience, that seems pretty clear to me, but the State type isn't the whole explanation. Check https://api.rocket.rs/rocket/struct.Rocket.html#method.manage https://api.rocket.rs/rocket/struct.Rocket.html#method.manag... too.
- vertex-four 10y agoGiven the description of State, the fact that it only has two methods to get at the inner value (.inner() and Deref::deref()), and each returns a different lifetime (one is 'r which is longer than or equal to the lifetime of the State, the other the lifetime of the State), it should be reasonably obvious to people who've coded Rust for a while. The example helps, obviously.
- tracker1 10y agoI'm not a rust guy, don't know it at all... and to me it's not too much different than interface/type definitions for the .Net framework in C#. It's often easier to work from examples though, but I do know that you often see interesting ways to do things when you look at API docs. OT: the framework looks interesting... routing as attributes is pretty cool, would be nice if one of the examples on the main page used a route variable though. I am curious how this compares in terms of requests/second of hello world vs. alternates... I would imagine the memory overhead would be much lower, but curious on throughput for the underlying model.
- vvanders 10y agoYeah, it's reasonably understandable. In fact it's a pretty awesome example of Rust's traits in practice since it requires Sync + Send so you know it needs to be thread safe(and the type system will enforce it).
- juancampa 10y agoI'm curious what's the difference between Managed State and good old Dependency Injection. Is it just a naming difference? In that case, why? People already know what DI is.
- yawgmoth 10y agoWhile I could see that this implementation of Managed State is an example of DI, the opposite is not true.
- azdle 10y agoIf there's anyone here with experience using both Rocket and Iron, would you be willing to share your thoughts on the differences between them? I've got an API server started in Iron, but I have to say the claims of productivity and less code overhead that Rocket is proclaiming seem pretty nice right about now.
- danaliv 10y agoI tried to build a simple Rust "hello world" + database web app the other day (edit: not with Rocket) and after four hours I had nothing to show for it. I had a simple static app in just a few minutes, but I could not for the life of me figure out how to maintain state like a database connection pool and make it available to request handlers in any sane and maintainable way. (There are ways to do it insanely and unmaintainably for sure.) Has anyone else had this experience?
- sbenitez 10y agoThanks for trying out Rocket! There are a couple of examples in Rocket's repository that illustrate how to use Rocket with a database. The more complete of the two is the todo example [0]. This uses Diesel as its ORM alongside managed state to maintain a pool of database connections. The second example of the two uses raw SQLite without a connection pool [1]. It's meant to be a bare bones illustration of using a database with Rocket. Managed state is a feature specifically designed to help with this kind of thing. That being said, I still think Rocket can do more to abstract away database connections. I'm tracking improvements on this front in GitHub issue #167 [2]. [0]: https://github.com/SergioBenitez/Rocket/tree/master/examples/todo https://github.com/SergioBenitez/Rocket/tree/master/examples... [1]: https://github.com/SergioBenitez/Rocket/blob/master/examples/raw_sqlite https://github.com/SergioBenitez/Rocket/blob/master/examples... [2]: https://github.com/SergioBenitez/Rocket/issues/167 https://github.com/SergioBenitez/Rocket/issues/167
- danaliv 10y agoThanks so much for the helpful reply! I should've noted that I haven't actually tried Rocket. :) It was a couple other frameworks that I'd played with, all of which seemed to go shrug, not our concern when the question of managed state came up. I'll give Rocket a try and see if I have better luck.
- bjz_ 10y agoI was actually going to use `lazy_static!` for this! Good to see a nicer solution is now here. :)
- mattrb 10y agoDoes Rocket have subdomain support? I didn't see it in the documentation.
- onmobiletemp 10y agoKeep it up sergio!
- Daishiman 10y agoI have to say, the end user API for Rocket is pretty nice. But damn, there's a lot of compiler magic in order to simplify the request and response signatures. It would be great to see more documentation on how to deal with naked Request/Response objects that can be constructed by hand. I'd love to use Rocket to develop some API on top of it, but that means I want more access to the underlying objects below.
- fanyer 10y agoSeems good. I'll taste it