Creating our first Rocket web application
In this section, we are going to create a very simple web application that handles only one HTTP path. Follow these steps to create our first Rocket web application:
- Create a new Rust application using Cargo:
cargo new 01hello_rocket --name hello_rocket
We are creating an application named hello_rocket
in a folder named 01hello_rocket
.
- After that, let's modify the
Cargo.toml
file. Add the following line after[dependencies]
:rocket = "0.5.0-rc.1"
- Append the following lines at the top of the
src/main.rs
file:#[macro_use] extern crate rocket;
Here, we are telling the Rust compiler to use macros from the Rocket crate by using the #[macro_use]
attribute. We can skip using that attribute, but that would mean we must specify use
for every single macro that we are going to use.
- Add the following line to tell the compiler that we are using the definition from the Rocket crate:
use rocket::{Build...