group

Macro group 

Source
macro_rules! group {
    ($prefix:expr, { $( $item:expr ),* $(,)? }) => { ... };
}
Expand description

Define a route group with a shared prefix

Routes within a group will have the prefix prepended to their paths. Middleware can be applied to the entire group using .middleware(). Groups can be nested arbitrarily deep.

§Example

use kit::{routes, get, post, group};

routes! {
    get!("/", controllers::home::index),

    // All routes in this group start with /api
    group!("/api", {
        get!("/users", controllers::user::index),      // -> GET /api/users
        post!("/users", controllers::user::store),     // -> POST /api/users

        // Nested groups are supported
        group!("/admin", {
            get!("/dashboard", controllers::admin::dashboard), // -> GET /api/admin/dashboard
        }),
    }).middleware(AuthMiddleware),  // Applies to ALL routes including nested
}

§Middleware Inheritance

Middleware applied to a parent group is automatically inherited by all nested groups. The execution order is: parent middleware -> child middleware -> route middleware.

§Compile Error

Fails to compile if prefix doesn’t start with ‘/’.