Table of Contents
- Install RUST on Ubuntu
- Setup SALVO in your RUST project
- Setup Basic server to listen to GET request
- Create simple read operation route from MySQL
- Create write operation route
- Create udate operation route
- Create delete operation route
- Download Source Code
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;
}