[−][src]Struct hreq::server::Router
Encapsulate chains of Middleware
and Handler
.
Inside Server
there is always a default router which is configured
via Server::at
, however routers can also be instantiated and configured
separately. This can be a good strategy for complex servers with many
subsystems.
Example
use hreq::prelude::*; async fn start_server() { let mut server = Server::new(); let mut router = Router::new(); router.at("/hello/:name").get(hello_there); // Resulting route is /much/hello/<name> server.at("/much").router(router); server.listen(3000).await.unwrap(); } async fn hello_there(req: http::Request<Body>) -> String { format!("Hello {}", req.path_param("name").unwrap()) }
Implementations
impl<State> Router<State> where
State: Clone + Unpin + Send + Sync + 'static,
[src]
State: Clone + Unpin + Send + Sync + 'static,
pub fn new() -> Router<State>
[src]
Creates a new router.
pub fn at(&mut self, path: &str) -> Route<'_, State>
[src]
Configure an route for this server.
A route is a chain of zero or more Middleware
followed by a Handler
.
Reusing the same path
will overwrite the previous config.
Trait Implementations
Auto Trait Implementations
impl<State> !RefUnwindSafe for Router<State>
impl<State> Send for Router<State>
impl<State> Sync for Router<State>
impl<State> Unpin for Router<State>
impl<State> !UnwindSafe for Router<State>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,