Live data from Hacker News

Rocket, Rust Web Framework, v0.2: Managed State and More

rocket.rs

31–40 of 62 posts

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#32
post #29

I 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 unm…

Thanks 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...

[1]: https://github.com/SergioBenitez/Rocket/blob/master/examples...

[2]: https://github.com/SergioBenitez/Rocket/issues/167

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#33
post #29

I 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 unm…

Thanks 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 data…

Thanks 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.

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#34
post #5

Just 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 (screenshot: 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…

It is readable, but you are right it is terribly formatted with a lot of not-very-important information in huge fonts. I think rustdoc needs quite a lot of work in general. For example it doesn't even give a list of methods at the start of each type's page. Want to know which methods you can call on a `String`? Enjoy scrolling... https://doc.rust-lang.org/std/string/struct.String.html

> I think rustdoc needs quite a lot of work in general.

It does. Honestly, it's quite hard to contribute to at the moment. This is going to improve in the very near future; there's a PR in the queue that's the start of the ability to start making it easier. I hope to make it vastly so someday in the future. Always so much work to do...

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#35
post #30
post #18

Earlier quoted context omitted.

No. 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 clie…

Interesting. 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?

> 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.

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#36
post #18
post #7

Earlier quoted context omitted.

Are reverse proxies always the way to go?

No. 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 clie…

Practically every company I've worked with uses an HTTP reverse proxy. When you use something like nginx, it's really not hard at all to get right. Support for HTTP is more widespread than support for FastCGI these days, especially with more obscure tech stacks.

Edit: You can run multiple apps on separate ports, so that shouldn't be an issue.

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#37
post #35
post #30

Earlier quoted context omitted.

Interesting. 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?

> 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 w…

I 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

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#38
post #5

Just 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 (screenshot: 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…

The docs make sense once you get used to them and understand what they're telling you, but it does take some getting used to. The general output of rustdoc could also be improved in my opinion.

A bit more summary of available methods/trait impls somewhere would be nice.

I'd appreciate a three scrollable pane setup, first pane similar to whats already there on the left, but always visible. Second pane type, usage, examples, methods, impls. Third pane in the middle, widest, actual information in long form. Inline examples of each method are incredibly helpful and the std library docs have quite a few of those but not always. Its sometimes hard to understand how to use a method or type or impl depending on its signature.

Panes should scroll+highlight currently viewed items in the actual doc (third) pane.

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#39
post #18

Earlier quoted context omitted.

No. 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 clie…

Practically every company I've worked with uses an HTTP reverse proxy. When you use something like nginx, it's really not hard at all to get right. Support for HTTP is more widespread than support for FastCGI these days, especially with more obscure tech stacks. Edit: You can run multiple apps on separate ports, so that shouldn't be an issue.

> Practically every company I've worked with uses an HTTP reverse proxy.

Well, there are people who can say the same about Node.js or RoR. Not that it makes a majority.

> When you use something like nginx, it's really not hard at all to get right.

It's not a matter of nginx. It's a matter of what assumptions are hardcoded in the application.

> Edit: You can run multiple apps on separate ports, so that shouldn't be an issue.

Of course it is an issue. Such a deployment looks terrible at best.

Re: Rocket, Rust Web Framework, v0.2: Managed State and More

#40
post #29

I 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 unm…

Thanks 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 data…

I was actually going to use `lazy_static!` for this! Good to see a nicer solution is now here. :)
Post reply on HN