Setting up our server
When it comes to setting up a basic server in Rocket, we are going to start with everything defined in the main.rs
file. First, start a new Cargo project and then define the Rocket dependency in the Cargo.toml
file with the following code:
[dependencies] rocket = "0.5.0-rc.2"
This is all we need for now in terms of dependencies. Now, we can move to our src/main.rs
file to define the application. Initially, we need to import the Rocket crate and the macros associated with the Rocket crate with the following code:
#[macro_use] extern crate rocket;
We can now define a basic hello world view with the following code:
#[get("/")] fn index() -> &'static str { "Hello, world!" }
With the preceding code, we can deduce that the macro before the function defines the method and URL endpoint. The function is the logic that is executed when the call is made to the view, and whatever the function...