pub struct Router<'a, D> { /* private fields */ }
Expand description
A path-based HTTP router supporting exact-match or wildcard placeholders and shared data.
Implementations§
source§impl<'a, D: 'a> Router<'a, D>
impl<'a, D: 'a> Router<'a, D>
sourcepub fn with_data(data: D) -> Self
pub fn with_data(data: D) -> Self
Construct a new Router
with arbitrary data that will be available to your various routes.
sourcepub fn head(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn head( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to HEAD requests.
sourcepub fn get(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn get( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to GET requests.
sourcepub fn post(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn post( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to POST requests.
sourcepub fn put(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn put( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to PUT requests.
sourcepub fn patch(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn patch( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to PATCH requests.
sourcepub fn delete(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn delete( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to DELETE requests.
sourcepub fn options(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn options( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will exclusively respond to OPTIONS requests.
sourcepub fn on(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn on( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will respond to any requests.
sourcepub fn or_else_any_method(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> Result<Response>
) -> Self
pub fn or_else_any_method( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> Result<Response> ) -> Self
Register an HTTP handler that will respond to all methods that are not handled explicitly by other handlers.
sourcepub fn head_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn head_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to HEAD requests. Enables the use of
async/await
syntax in the callback.
sourcepub fn get_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn get_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to GET requests. Enables the use of
async/await
syntax in the callback.
sourcepub fn post_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn post_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to POST requests. Enables the use of
async/await
syntax in the callback.
sourcepub fn put_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn put_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to PUT requests. Enables the use of
async/await
syntax in the callback.
sourcepub fn patch_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn patch_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to PATCH requests. Enables the use of
async/await
syntax in the callback.
sourcepub fn delete_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn delete_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to DELETE requests. Enables the use
of async/await
syntax in the callback.
sourcepub fn options_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn options_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will exclusively respond to OPTIONS requests. Enables the use
of async/await
syntax in the callback.
sourcepub fn on_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn on_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will respond to any requests. Enables the use of async/await
syntax in the callback.
sourcepub fn or_else_any_method_async<T>(
self,
pattern: &str,
func: fn(_: Request, _: RouteContext<D>) -> T
) -> Selfwhere
T: Future<Output = Result<Response>> + 'a,
pub fn or_else_any_method_async<T>( self, pattern: &str, func: fn(_: Request, _: RouteContext<D>) -> T ) -> Selfwhere T: Future<Output = Result<Response>> + 'a,
Register an HTTP handler that will respond to all methods that are not handled explicitly by
other handlers. Enables the use of async/await
syntax in the callback.