5 unstable releases

0.3.0 Dec 24, 2020
0.2.10 Dec 22, 2020
0.2.0 Apr 26, 2020
0.1.6 Feb 23, 2020
0.1.5 Feb 21, 2020

#5 in #salvo

MIT license

4KB
67 lines

Salvo build statusbuild statusbuild statuscodecov crates.io

Salvo is a simple web framework written by rust. It is simple to use it to build website, REST API.

Features

  • Base on hyper, futures 0.3.
  • Easy to write router.

Quick start

You can view samples here or read docs here.

Create a new rust project:

cargo new salvo_taste --bin

Add this to Cargo.toml

[dependencies]
salvo = "0.3"
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(_conf: Arc<ServerConfig>, _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(_conf: Arc<ServerConfig>, _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 mut router = Router::new("/");
    router.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)

Dependencies

~315–740KB
~18K SLoC