REST API: Node vs Rust

Sean Wragg
Sean’s Blog
Published in
4 min readFeb 7, 2017

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)

Node (via Restify)

Run via node src/server.js - nothing really special here. restify pinned at version 4.0.3

node v6.9.5
npm 3.10.30

Developer Environment

Coming from a primarily Javascript heavy ecosystem (npm), I felt right at home with Rust. Cargo feels a lot like a merge between npm and any standard task runner (similar to Grunt or Gulp). Packages are called crates. Cargo creates a…

Sean Wragg
Sean’s Blog

Writing about code, comics, and fhqwhgads!