Function gotham::router::builder::build_router[][src]

pub fn build_router<C, P, F>(
    pipeline_chain: C,
    pipelines: PipelineSet<P>,
    f: F
) -> Router where
    C: PipelineHandleChain<P> + Copy + Send + Sync + 'static,
    P: Send + Sync + 'static,
    F: FnOnce(&mut RouterBuilder<'_, C, P>), 
Expand description

Builds a Router using the provided closure. Routes are defined using the RouterBuilder value passed to the closure, and the Router is constructed before returning.

Important note: The path passed to the RouterBuilder is decomposed in segments. This means that empty segments and trailing slashes are removed. Basically route.get("/foo//bar/baz/") will have the same effect as route.get("/foo/bar/baz")

fn router() -> Router {
    let (chain, pipelines) = single_pipeline(
        new_pipeline()
            .add(NewSessionMiddleware::default().with_session_type::<Session>())
            .build()
    );

    build_router(chain, pipelines, |route| {
        route.get("/request/path").to(my_handler);
    })
}