exum

Crates.ioexum
lib.rsexum
version0.2.0
created_at2025-10-04 04:35:14.144671+00
updated_at2025-10-07 07:06:28.172066+00
descriptionA lightweight Axum syntax sugar library
homepage
repositoryhttps://github.com/isyuah/exum
max_upload_size
id1867509
size98,015
芋 (isYuAh)

documentation

README

Exum

一个轻量级的 Axum 语法糖库,提供更简洁的路由定义语法。

特性

核心功能

  • 🚀 简洁的路由宏语法
  • 📦 自动参数提取和类型转换
  • 🔧 支持多种HTTP方法
  • 🎯 路径参数自动解析
  • 📝 查询参数和请求体处理
  • ⚡ 省略返回值时默认返回 impl IntoResponse
  • 🛠️ 快速响应构建器 - 便捷的HTTP响应构建函数
  • 📁 静态文件服务 - 支持SPA回退和URL编码路径

配置管理

  • 🌍 环境自动检测和配置覆盖
  • 🔧 环境变量注入支持
  • 📁 多环境配置文件管理

高级功能

  • 🔗 链式调用支持(AppChainExt)
  • 💉 依赖注入支持(状态管理和自动注入)
  • ⚠️ Controller 宏(支持分组路径前缀,使用前必须阅读文档!)

安装

Cargo.toml 中添加依赖:

[dependencies]
exum = "0.1.0"

快速开始

use exum::*;

#[get("/hello/:id")]
async fn hello(id: String, #[q] q: String) -> String {
    format!("id: {}, query: {}", id, q)
}

#[post("/users")]
async fn create_user(#[b] user: User) -> String {
    format!("Created user: {:?}", user)
}

// 使用 #[main] 宏自动处理应用初始化和配置加载
#[main]
async fn main() {
    
}

// 或者使用传统方式手动初始化
// #[tokio::main]
// async fn main() {
//     let app = Application::build(ApplicationConfig::default());
//     app.run().await;
// }

文档

详细的文档请参考以下章节:

Features

  • deref-app: 为 Application 实现 Deref trait,可以直接访问底层的 Router
  • app_chain_ext: 为 Application 提供链式调用方法,支持更灵活的路由配置
  • app_chain_ext_full: 包含 app_chain_ext 和静态文件服务功能
  • layers: 获得一些Service, Layer以及fast_builder(如StaticFileServiceBuilder)
  • full: 包含所有特性

许可证

MIT License

Commit count: 0

cargo fmt