salvo 0.5.0

A simple web framework
Documentation

build status build status build status codecov crates.io Download License

Features

  • Base on hyper, tokio.
  • Tree-like routing system.

Quick start

You can view samples here or read docs here.

Create a new rust project:

cargo new hello_salvo --bin

Add this to Cargo.toml

[dependencies]
salvo = "0.4"
tokio = { version = "1.0", features = ["full"] }

Create a simple function handler in the main.rs file, we call it hello_world, this function just render plain text "Hello World".

use salvo::prelude::*;

#[fn_handler]
async fn hello_world(_req: &mut Request, _depot: &mut Depot, res: &mut Response) {
    res.render_plain_text("Hello World");
}

In the main function, we need to create a root Router first, and then create a server and call it's serve function:

use salvo::prelude::*;

#[fn_handler]
async fn hello_world(_req: &mut Request, _depot: &mut Depot, res: &mut Response) {
    res.render_plain_text("Hello World");
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let router = Router::new().get(hello_world);
    let server = Server::new(router);
    server.serve().await?;
    Ok(())
}

License

Salvo is licensed under MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)