简单强大的 Rust Web 框架,Salvo 0.24.2 发布

科技资讯 投稿 50500 0 评论

简单强大的 Rust Web 框架,Salvo 0.24.2 发布

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

编程笔记 » 简单强大的 Rust Web 框架,Salvo 0.24.2 发布

赞同 (24) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽