Skip to content

Latest commit

 

History

History
90 lines (70 loc) · 3.34 KB

File metadata and controls

90 lines (70 loc) · 3.34 KB

WebR Logo

English · 文档

WebR 将 Spring Boot 的开发体验带入 Rust 生态 —— 宏驱动的控制器、自动依赖注入、配置管理、中间件系统、ORM、缓存,构建于 Axum 之上。

use webr::prelude::*;

#[controller]
pub struct HelloController;

#[controller]
impl HelloController {
    #[get("/")]
    async fn index(&self) -> String {
        "hello world".to_string()
    }
}

#[webr::main]
async fn main(_app: &mut AppBuilder) -> Result<()> {
    Ok(())
}

如果一切正常,访问 http://localhost:8080 即可看到 hello world

文档

完整文档见 WebR Document

示例

examples 目录下,提供了一些示例项目,可以通过这些示例来快速了解 WebR 的使用。

示例 说明
hello-world 控制器、依赖注入、配置绑定、统一响应
middleware 自定义认证中间件、路径范围路由、CORS
file-upload 多文件上传、文件下载、内联预览
sse Server-Sent Events 服务端推送
orm 实体 CRUD、#[sql] 动态查询、#[tx] 事务
cache 缓存模块使用
axum-bench 原生 axum 与 WebR 性能对比基准

运行示例:

cd examples/hello-world
cargo run

项目结构

webr/
├── crates/
│   ├── webr-core/        # 核心基础:DI、配置、上下文、Inject、Error
│   ├── webr-web/         # Web 层:AppBuilder、提取器、中间件、响应、路由
│   ├── webr-db/          # 数据库:连接池、事务、ORM 支持
│   ├── webr-cache/       # 缓存:内存 / Sled / Redis 多后端
│   ├── webr-macros/      # 过程宏:controller、component、config、entity、sql、tx、HttpError
│   └── webr-middleware/  # 中间件:认证、鉴权、请求体缓存
├── examples/             # 示例应用
└── src/lib.rs            # Umbrella crate,统一导出所有公共 API

许可证

Apache 2.0