Live data from Hacker News

Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

rocket.rs

61–70 of 75 posts

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#61
post #56
post #33

It's really a shame they haven't jumped on tokio yet. Then again, I tried to look at the code, and it didn't seem to be a simple dropin thing to move over to tokio.

It's far from clear if tokio is not a dead end.

How so?

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#63
post #53

Earlier quoted context omitted.

Isn't Postgres worth coupling to? SQLite is a close favorite, for different reasons.

Web servers and database management are two vastly different domains. I'm wary of frameworks that attempt to impose an opinion on both.

Rocket isn't a web server, it's a web framework. That's what frameworks should do, impose opinions on things to get all the best practices sorted.

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#64
post #38

I'm a Rocket fan and glad to see this big slate of improvements. On the other hand, I do want to register a bit of concern regarding the plan to add "first-class database support" for 0.4. I hope that doesn't result in a close coupling to any particular database, or to using a database in general.

Database support will live outside of Rocket's core in Rocket's contrib [0] library. Everything in contrib is implemented independently of Rocket and is entirely optional to use. The implementation will be database agnostic and extensible to any database. I'm a big believer in pluggable, optional components with no forced decisions [1], and database support will follow the same philosophy.

[0]: https://api.rocket.rs/rocket_contrib/index.html

[1]: https://rocket.rs/guide/introduction/#foreword

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#65
post #28

Hey Sergio, Regarding fairings, it seems a missing "middleware" case might be the sorts of things that cause redirects on entry (e.g. redirect routes with/without trailing slashes to the latter as a super trivial example). Is that something you'd expect to support in some way? I think that's something that doesn't feel like it maps either to guards or fairings well at the moment. I did see where you mentioned your di…

This is actually possible with fairings! Because fairings can rewrite requests, it's possible to create a fairing that rewrites a request URI of `path/` to `path` or vice-versa as needed. Rocket will route the rewritten request normally. In psuedocode, such a fairing might look like:

  on_request => |request, _| {
      if request.uri().path().ends_with('/') {
          let new_path = request.uri().path()[..-1];
          request.set_uri(URI::new(new_path));
      }
  }
You can also use a fairing If you want to return a 302 (or similar) so that the browser does the redirect instead. In this case, you'd implement a response fairing that rewrites failed responses to return a redirect to the appropriate URI. Again, in pseudocode, this would look like:

  on_response => |request, response| {
      if response.status() == Status::NotFound && request.uri().path().ends_with('/') {
          response.set_status(Status::Found);
          response.set_header(Location(request.uri().path()[..-1]));
          response.take_body();
      }
  }
Take a look at the fairings guide [0] and fairings documentation [1] for more ideas!

[0]: https://rocket.rs/guide/fairings/

[1]: https://api.rocket.rs/rocket/fairing/trait.Fairing.html

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#66

Earlier quoted context omitted.

For that list of features and the discussion around them, https://github.com/SergioBenitez/Rocket/issues/19

i128 really surprises me. Why would a web framework need 128 bit integers?

It appears u128s are used to intern strings. i.e. efficient uuids.

https://github.com/SergioBenitez/Rocket/blob/master/codegen/...

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#67
post #20

I don't have any experience in Rust. From what I read, Rust is a low level / system programming language. Comparing to dynamic languages like Python, I understand that Rust is much faster. However, Python is fast enough for most web applications. So why should I use Rust in web development? Even if the library ecosystem were mature enough, could I expect my productivity could become nearly high as in Python?

I'd say it's true that Python is fast enough for most web servers. Rather than strictly considering performance, I'd guess that people seeking to do webdev in Rust are looking to leverage Rust's static analysis to improve resilience, trading off up-front productivity for long-term maintainability (which isn't to denigrate Python, which I love, but fearless refactoring really is something that compiled langs excel at)…

> fearless refactoring really is something that compiled langs excel at

Would you say that's a feature of compilation? I'd have said it's Rust's strong and static type system that makes refactoring 'fearless' and generally aids productivity and maintainability.

Python ≥3.6 with liberal type hinting is a more interesting comparison in my view.

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#68

Earlier quoted context omitted.

Isn't Postgres worth coupling to? SQLite is a close favorite, for different reasons.

As someone who only uses Postgres and SQLite: No. It's not. People inevitably have to deal with preexisting systems they can't modify for their needs.

Should a framework optimize for the vanishingly rare case?

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#69
post #62

Earlier quoted context omitted.

How so?

Overly complicated

I'm not sure it is an issue of complexity. From what I have seen, it is more a problem of ergonomics. Currently, programming something fairly simple with a few loops and if statements using Futures is painful, but I could see a Futures-based async/await version take off.

Re: Rocket, Rust Web Framework, v0.3: Fairings, TLS, Private Cookies

#70

How is the performance of Rocket? So far all the Rust web frameworks I've seen have pretty disappointing performances. I was expecting C++/Java/Go level of performance. Instead, Tokio & Iron turn out to be slower than many frameworks in Ruby, Python, PHP, JS: https://www.techempower.com/benchmarks/#section=data-r14&hw=... https://www.techempower.com/benchmarks/#section=data-r14&hw=... https://www.techempower.com/benc…

* iron isn't using async io which is very important for Techempower * Tokio-minihttp is #4 overall on the plaintext benchmark there, which is sort of the "what is the max performance" benchmark I don't know of anyone who is really actively looking at Techempower and optimizing based on it, which is how you win benchmarks.

How is the async web server story looking? I keep thinking I'd like to port a small tornado app to Rust, but I'd rather it was fairly easy for some to verify it was behavioural similar.

(Literally, I don't care about the performance, I just want that style of API.)

Post reply on HN