Attribute Macro actix_web::scope

source ·
#[scope]
Available on crate feature macros only.
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!"
    }
}