REST API: Node vs Rust
With all the hype surrounding Rust, I’ve decided to take a closer look. So I spent about an hour or so looking over the Rust Docs and admittingly, it looks like a really fun language.
However, I wanted to see how it’d stack up against my current favorite web layer Node.js using the Restify framework. To do this, I’ve decided to use Rocket as my Rust web framework. I did notice Iron and several other Rust web frameworks but, I really liked the simplicity of the Rocket interface. I think nickel would have been my next choice.
Below we have a snippet for Rocket and another for Restify.
Rust (via Rocket)
Compiled via cargo build --release
using rustup default nightly
(as required by Rocket). rocket
and rocket_codegen
pinned at version 0.2.0
.
It’s also worth pointing out that Rocket relies on a ROCKET_ENV
environment variable which can be found under the Environment section of the docs (thanks @SergioB!) and can be set to either development
, staging
or production
. It's important to set this to production
otherwise Rocket will run in development mode by default regardless of using the --release
flag in cargo.
rustc 1.17.0-nightly (ea7a6486a 2017-02-04)
cargo-0.18.0-nightly (d710222 2017-02-04)