Skip to main content

router

Macro router 

Source
macro_rules! router {
    ($state:ty $(, $routes:expr)+ $(,)?) => { ... };
}
Available on crate feature http only.
Expand description

Assemble a router from several api! modules, with the context layer already attached.

api! writes a routes() per resource, which leaves two things to remember at the top level: merging them, and calling layer(). Forgetting the second is not a subtle bug — every request becomes a 500, because no handler can find its Context — so it is worth not being able to forget.

ⓘ
mod todos { ash_jsonapi::api! { /* … */ } }
mod users { ash_jsonapi::api! { /* … */ } }

let app = ash_jsonapi::router!(App, todos::routes(), users::routes());

Equivalent to merging each router, adding layer(), and calling .with_state(…) yourself — write that out when you need another layer in between.