A blog with the web framework Rocket - part 1

A Hello, world! with Rocket

Rust environment

Currently a rocket application needs to be compiled using latest nightly Rust. So install it, if you don't have it yet:

$ rustup install nightly

If nightly Rust was install but not up to date, update it and also check that Cargo is too:

$ rustup update && cargo update

Create your blog Rust project

$ cargo new blog-rs

Go into this new project:

$ cd blog-rs

Set use of nightly rust for this project:

$ rustup override set nightly

You can check that everything went well:

$ cargo run
   Compiling blog-rs v0.1.0 (/home/ecolin/Workspace/blog-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 0.73s
     Running `target/debug/blog-rs`
Hello, world!

It works!!!

Alright, now we can install Rocket.

Rocket installation

Cargo file configuration

According to Rocket website we should first set the Cargo file up:

[package]
name = "blog-rs"
version = "0.1.0"
authors = ["my_user_name <my_mail>"]
edition = "2018"

[dependencies]
rocket = "0.4.0"

Launching the rocket

Now concerning src/main.rs, place these lines into it:

#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use]
extern crate rocket;

#[get("/")] // A route home is created
fn home() -> &'static str { 
    "Hello, world!"
}

fn main() {
    rocket::ignite()
    .mount("/", routes![index]) // The route is mounted at the / path
    .launch(); The app is launched!
}

In your browser, at the url http://localhost:8000 you should see your first Hello, world! with Rocket.