Create simple CRUD app using RUST salvo Framework with MySQL db

Table of Contents

  1. Install RUST on Ubuntu
  2. Setup SALVO in your RUST project
  3. Setup Basic server to listen to GET request
  4. Create simple read operation route from MySQL
  5. Create write operation route
  6. Create udate operation route
  7. Create delete operation route
  8. Download Source Code
All right lets go, but first even before gettting started with SALVO framework we need to understand why rust? that will give us good understanding why do we want to consider RUST as a option

Install RUST on Ubuntu

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Validate if your installation is done or not using

rustc --version

Cargo it is the Rust build tool and package manager

cargo --version

If you see version name great! If not google it :) because on job no one is going to spoon-feed you, you have figure out yourself

Setup SALVO in your RUST project

Create a new RUST project using command

cargo new hello_salvo --bin

Open hello_salvo folder in your editor VSCODE or sublime. you should be able to see cargo.toml and main.rs file. Add below code in cargo.toml

[dependencies]
salvo = "*"
tokio = { version = "1", features = ["macros"] }

Setup Basic server to listen to GET request

in main.rs file paste below code

use salvo::prelude::*;

#[handler]
async fn hello() -> &'static str {
    "Hello World"
}

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt().init();

    let router = Router::new().get(hello);
    let acceptor = TcpListener::new("127.0.0.1:5800").bind().await;
    Server::new(acceptor).serve(router).await;
}