Rust is a systems programming language that runs extremely quickly, prevents segfaults, and guarantees thread safety. Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety. All with minimal code.
I’ve put together a Dockerfile that helps in the deployment of a Rocket web app, where the setup for the running environment and the serve process have been configured.
- The rustup docker image is used, which is built over debian, and comes with
- The source files for the Rocket app are placed at
srcdirectory. So, if you have an existing Rocket app to deploy, you can replace the contents in
srcdirectory with it.
- Rocket makes abundant use of Rust’s syntax extensions and other advanced, unstable features. Because of this, a nightly version of Rust is to be used, which is done with the
- Cargo is the Rust package manager. Cargo downloads your Rust project’s dependencies. We build the project using
- And we run the project with
cargo run, which runs the project at
Adding backend features to Rocket
Comparison of nodeJS-Express and Rust-Rocket Request and Transfer time:
Note that the Rocket web-app was built with the
— release flag.
cargo build --release puts the resulting binary in
target/release instead of
target/debug. Compilation time is shorter in debug since the compiler doesn’t do optimizations, but the code will run slower. Release mode takes longer to compile, but the code will run faster. You can add the
— release flag in the
cargo build command in the Dockerfile if you’re planning to use it for production.
I’ve put together a Hasura platform quickstart for the Rocket framework.
To try a sample Rust Rocket project on The Hasura platform (it’s free and it’ll only take you a few minutes):
- Install the Hasura CLI tool.
- Run this command (you can copy the entire section below and run in one shot).
hasura quickstart anirudhm/hello-rust-rocket && cd
Read more about this quickstart here: https://hasura.io/hub/project/anirudhm/hello-rust-rocket.
I would love to hear your feedback on this, let me know in the comments below :)