#salvo #web #framework #server

salvo_core

A simple web framework written by rust

13 releases (4 breaking)

new 0.5.4 Jan 21, 2021
0.5.3 Jan 21, 2021
0.4.5 Jan 19, 2021
0.3.1 Dec 27, 2020
0.1.6 Feb 23, 2020

#326 in HTTP server

Download history 7/week @ 2020-09-30 3/week @ 2020-10-07 3/week @ 2020-10-14 6/week @ 2020-10-21 3/week @ 2020-10-28 4/week @ 2020-11-04 2/week @ 2020-11-11 3/week @ 2020-11-18 6/week @ 2020-11-25 7/week @ 2020-12-02 5/week @ 2020-12-09 15/week @ 2020-12-16 51/week @ 2020-12-23 25/week @ 2020-12-30 41/week @ 2021-01-06 135/week @ 2021-01-13

123 downloads per month
Used in 2 crates

MIT license

225KB
5K SLoC

Salvo

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

Salvo is a simple web framework written by rust.

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.bind(([0, 0, 0, 0], 7878)).await?;
    Ok(())
}

License

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

Dependencies

~11–15MB
~307K SLoC