Salvo 0.24.2 更新内容:
添加了 test 模块, 方便单元测试, 比起之前使用 http::Request::builder 构建 Request 请求简洁很多。
添加解析 Request 请求数据到强类型的功能, 并且支持多数据源组合.
Salvo 是极其简单且功能强大的框架
Handler
use salvo::prelude::*;
#[fn_handler]
async fn hello_world(_req: &mut Request, _depot: &mut Depot, res: &mut Response {
res.render(Text::Plain("Hello World"; }
中间件
use salvo::http::header::{self, HeaderValue};
use salvo::prelude::*;#[fn_handler]
async fn add_header(res: &mut Response {
res.headers_mut( .insert(header::SERVER, HeaderValue::from_static("Salvo"; }
路由
Router::new(.push(
Router::with_path("articles"
.get(list_articles
.push(Router::with_path("".get(show_article,
.push(
Router::with_path("articles"
.hoop(auth_check
.post(list_articles
.push(Router::with_path("".patch(edit_article.delete(delete_article,
;
Github: https://github.com/salvo-rs/salvo