Attribute Macro actix_web_codegen::scope

source ·
#[scope]
Expand description

Prepends a path prefix to all handlers using routing macros inside the attached module.

§Syntax

#[scope("/prefix")]
mod api {
    // ...
}

§Arguments

  • "/prefix" - Raw literal string to be prefixed onto contained handlers’ paths.

§Example

#[scope("/api")]
mod api {
    #[get("/hello")]
    pub async fn hello() -> impl Responder {
        // this has path /api/hello
        "Hello, world!"
    }
}