Crates.io | salvo_macro |
lib.rs | salvo_macro |
version | 0.3.0 |
source | src |
created_at | 2020-02-21 23:14:43.410547 |
updated_at | 2020-12-24 01:18:55.360391 |
description | salvo proc macros |
homepage | https://github.com/kenorld/salvo |
repository | https://github.com/kenorld/salvo/macros |
max_upload_size | |
id | 211328 |
size | 4,447 |
Salvo is a simple web framework written by rust. It is simple to use it to build website, REST API.
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(())
}
Salvo is licensed under MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)