-
Hey! I'm working on a Web-facing app and I've taken akin to the whole "every endpoint is an action" kind of thing (like how REST and HATEOS tries to teach). Below is what my code looks like - still scaffolding it. mod api {
use trillium::{Conn, Handler};
use trillium_router::Router;
mod attestor {
use super::*;
async fn get_for_url(conn: Conn) -> Conn {
todo!()
}
async fn create_challenge(conn: Conn) -> Conn {
todo!()
}
async fn validate_challenge(conn: Conn) -> Conn {
todo!()
}
async fn delete(conn: Conn) -> Conn {
todo!()
}
pub fn router() -> impl Handler {
Router::new()
.get("/find", get_for_url)
.post("/challenge", create_challenge)
.post("/challenge/validate", validate_challenge)
.delete("/:id", delete)
}
}
mod identity {
use super::*;
async fn create(conn: Conn) -> Conn {
todo!()
}
async fn delete(conn: Conn) -> Conn {
todo!()
}
pub fn router() -> impl Handler {
Router::new().post("/new", create).delete("/:id", delete)
}
}
pub fn router() -> impl Handler {
// FIXME: Split out the following routes into sub-routers.
(attestor::router(), identity::router())
}
} At the bottom, you'd notice that I do the implicit casting of the two routers together to "merge" them. To be honest, I'd like to treat them as individual "apps" or like engines in the spirit of Rack or Plug. How do you think this should work? I was hoping to do something like // ...
attestor::router().with_route_prefix("/attestor"), identity::router().with_route_prefix("/identity")
// ... So I could remove the needed duplication in the route path definitions (I didn't add them here because that actually inspired this topic). I'd also hope that if I could prefix with Let me know if this makes sense (or not!) and if I can clarify anything. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
For a performance cost on the order of nanoseconds, you can mount the routers inside of an outer router, as in this example. Does that meet the |
Beta Was this translation helpful? Give feedback.
-
That approach works for me! Thanks for clarifying that, I wasn't too sure if |
Beta Was this translation helpful? Give feedback.
For a performance cost on the order of nanoseconds, you can mount the routers inside of an outer router, as in this example. Does that meet the
with_route_prefix
need, or is it important that this is defined on the inner routers?