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 report(
self,
pattern: &str,
func: fn(Request, RouteContext<D>) -> Result<Response>,
) -> Self
pub fn report( self, pattern: &str, func: fn(Request, RouteContext<D>) -> Result<Response>, ) -> Self
Register an HTTP handler that will exclusively respond to REPORT 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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn head_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn get_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn post_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn put_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn patch_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn delete_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn options_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn on_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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: impl Fn(Request, RouteContext<D>) -> T + 'a,
) -> Self
pub fn or_else_any_method_async<T>( self, pattern: &str, func: impl Fn(Request, RouteContext<D>) -> T + 'a, ) -> Self
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.