Savlo

[![build status](https://github.com/salvo-rs/salvo/workflows/CI%20(Linux)/badge.svg?branch=master&event=push)](https://github.com/salvo-rs/salvo/actions) [![build status](https://github.com/salvo-rs/salvo//workflows/CI%20(macOS)/badge.svg?branch=master&event=push)](https://github.com/salvo-rs/salvo/actions) [![build status](https://github.com/salvo-rs/salvo/workflows/CI%20(Windows)/badge.svg?branch=master&event=push)](https://github.com/salvo-rs/salvo/actions)
[![codecov](https://codecov.io/gh/salvo-rs/salvo/branch/master/graph/badge.svg)](https://codecov.io/gh/salvo-rs/salvo) [![crates.io](https://img.shields.io/crates/v/salvo)](https://crates.io/crates/salvo) [![Download](https://img.shields.io/crates/d/salvo.svg)](https://crates.io/crates/salvo) ![License](https://img.shields.io/crates/l/salvo.svg)

Salvo is a easy to use web framework written by rust.

🎯 Features

⚡️ Quick start

You can view samples here or read docs here.

Create a new rust project: bash cargo new hello_salvo --bin

Add this to Cargo.toml toml [dependencies] salvo = "0.8" tokio = { version = "1", 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".

```rust use salvo::prelude::*;

[fn_handler]

async fn helloworld(req: &mut Request, depot: &mut Depot, res: &mut Response) { res.renderplain_text("Hello World"); } ```

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

```rust use salvo::prelude::*;

[fn_handler]

async fn helloworld(res: &mut Response) { res.renderplain_text("Hello World"); }

[tokio::main]

async fn main() { let router = Router::new().get(hello_world); let server = Server::new(router); server.bind(([0, 0, 0, 0], 7878)).await; } ```

Tree-like routing system

```rust use salvo::prelude::*;

[tokio::main]

async fn main() { let router = Router::new() .get(index) .push( Router::new() .path("users") .before(auth) .post(createuser) .push(Router::new().path(r"").post(updateuser).delete(deleteuser)), ) .push( Router::new() .path("users") .get(listusers) .push(Router::new().path(r"").get(show_user)), );

Server::new(router).bind(([0, 0, 0, 0], 7878)).await;

}

[fn_handler]

async fn index(res: &mut Response) { res.renderplaintext("Hello world!"); }

[fn_handler]

async fn auth(res: &mut Response) { res.renderplaintext("user has authed\n\n"); }

[fn_handler]

async fn listusers(res: &mut Response) { res.renderplain_text("list users"); }

[fn_handler]

async fn showuser(res: &mut Response) { res.renderplain_text("show user"); }

[fn_handler]

async fn createuser(res: &mut Response) { res.renderplain_text("user created"); }

[fn_handler]

async fn updateuser(res: &mut Response) { res.renderplain_text("user updated"); }

[fn_handler]

async fn deleteuser(res: &mut Response) { res.renderplain_text("user deleted"); }

```

More Examples

Your can find more examples in examples folder: - basicauth.rs - compression.rs - filelist.rs - proxy.rs - remoteaddr.rs - routing.rs - ssechat.rs - sse.rs - tls.rs - todos.rs - unixsocket.rs - wschat.rs - ws.rs

☕ Supporters

Salvo is an open source project. If you want to support Salvo, you can ☕ buy a coffee here.

⚠️ License

Salvo is licensed under either of * Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) * MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)