pub struct Builder<Chain: RouterChain + Send + Unpin + 'static + Sync> { /* private fields */ }
Expand description
Builder type for the router
Implementations§
source§impl<Controllers: 'static + RouterChain + Unpin + Send + Sync> Builder<Controllers>
impl<Controllers: 'static + RouterChain + Unpin + Send + Sync> Builder<Controllers>
sourcepub fn route<H>(self, route: &str, method: Method, handler: H) -> Selfwhere
H: 'static + DynHandler<Body> + Send + Sync,
pub fn route<H>(self, route: &str, method: Method, handler: H) -> Selfwhere H: 'static + DynHandler<Body> + Send + Sync,
Add a simple request handle to a given path
// Simply declare a handler fn
async fn simple_handler(req: Request<Body>) -> impl Responder {200}
// Then while building your server
// ...
builder.route("/simple", Method::GET, simple_handler);
// ...
sourcepub fn route_with_guards<H, F, Chain>(
self,
route: &str,
method: Method,
handler: H,
guards: F
) -> Selfwhere
H: 'static + DynHandler<Body> + Send + Sync,
F: FnOnce(GuardBuilder<GuardChainEnd>) -> GuardBuilder<Chain>,
Chain: GuardChain + 'static,
pub fn route_with_guards<H, F, Chain>( self, route: &str, method: Method, handler: H, guards: F ) -> Selfwhere H: 'static + DynHandler<Body> + Send + Sync, F: FnOnce(GuardBuilder<GuardChainEnd>) -> GuardBuilder<Chain>, Chain: GuardChain + 'static,
Add a request handler to a given path behind guards
async fn handler(req: Request<Body>) -> impl Responder { 200 }
async fn value_guard(req: Request<Body>) -> Result<Request<Body>, u16> {
match req.captures().get("value") {
Some(v) if v.eq("allowed_value") => Ok(req),
Some(_) => Err(403),
None => Err(400),
}
}
builder.route_with_guards("/handler/{value}", Method::GET, handler, |g| {
g.apply(value_guard)
});
// ...
sourcepub fn controller<C: Controller + Send + Unpin + Sync>(
self,
controller: C
) -> Builder<RouterChainLink<C, Controllers>>
pub fn controller<C: Controller + Send + Unpin + Sync>( self, controller: C ) -> Builder<RouterChainLink<C, Controllers>>
Add a simple request handle to a given path
// Implement controller for your struct
struct SimpleController;
// Then while building your server
// ...
builder.controller(SimpleController);
// ...