salvo_macro

Crates.iosalvo_macro
lib.rssalvo_macro
version0.3.0
sourcesrc
created_at2020-02-21 23:14:43.410547
updated_at2020-12-24 01:18:55.360391
descriptionsalvo proc macros
homepagehttps://github.com/kenorld/salvo
repositoryhttps://github.com/kenorld/salvo/macros
max_upload_size
id211328
size4,447
Chrislearn Young (chrislearn)

documentation

README

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)

Commit count: 0

cargo fmt