#spring #macro #docs #attributes #path #routing #handler

过程宏 spring-macros

Rust 微服务框架

6 个版本

0.0.7 2024 年 8 月 21 日
0.0.6 2024 年 8 月 17 日

过程宏 中排名第 1728

Download history 283/week @ 2024-08-05 240/week @ 2024-08-12

每月下载量 523
用于 9 个 Crates(直接使用 2 个)

MIT 许可证

36KB
767 行代码(不包括注释)

spring.rs 的路由和运行时宏。

spring.rs 重新导出

spring.rs 完整重新导出此 crate 的版本,因此通常您不需要显式指定对此 crate 的依赖。然而,有时在更新 spring.rs 依赖项之前,会对此 crate 进行更新。因此,此处将展示显式导入的代码示例。请查看最新的 [spring.rs 属性文档],以了解哪些宏被重新导出。

单方法处理器

有一个宏用于为最常见的 HTTP 方法设置处理器,同时也定义了额外的守卫和特定路由的中间件。

请参阅文档:[GET],[POST],[PATCH],[PUT],[DELETE],[HEAD],[CONNECT],[OPTIONS],[TRACE]

#[get("/test")]
async fn get_handler() -> impl IntoResponse {
    "hello world"
}

多方法处理器

类似于单方法处理器宏,但接受一个或多个参数,用于指定它应该响应的 HTTP 方法。请参阅 [macro@route] 宏文档。

#[route("/test", method = "GET", method = "HEAD")]
async fn get_and_head_handler() -> impl IntoResponse {
    "hello world"
}

多路径处理器

充当多个单方法处理器宏的包装器。它不接受任何参数,并将这些参数委托给单个方法的宏。请参阅 [macro@routes] 宏文档。

#[routes]
#[get("/test")]
#[get("/test2")]
#[delete("/test")]
async fn example() -> impl IntoResponse {
    "hello world"
}

依赖关系

~240–680KB
~16K 行代码