poem icon indicating copy to clipboard operation
poem copied to clipboard

Add support for merging routes/endpoints

Open choco opened this issue 2 years ago • 0 comments

It would be nice if there was support for merging routes like Axum, this is especially usefull when breaking down routes in multiple modules.

Description of the feature

The feature is well described here https://docs.rs/axum/latest/axum/routing/struct.Router.html#method.merge I tried to replicate the same in poem with nest but it panics complaining about duplicate entries.

In my case for example I'd like to have somethign like this.

mod module_a {
  fn routes() -> impl Endpoint { todo!() }
}

mod module_b {
  fn routes() -> impl Endpoint { todo!() }
}

let routes_a = module_a::routes();
let routes_b = module_b::routes();
let final_routes = Routes::new()
    .merge(routes_a)
    .merge(routes_b)
    .with(Tracing);

choco avatar Sep 27 '22 16:09 choco