Struct hreq::server::Route [−][src]
A route as obtained by Server::at
or Router::at
.
Implementations
impl<'a, State> Route<'a, State> where
State: Clone + Unpin + Send + Sync + 'static,
[src]
State: Clone + Unpin + Send + Sync + 'static,
pub fn middleware<M: Middleware>(self, middleware: M) -> Self
[src]
Attach Middleware
.
Middleware must be added before handlers that are to be affected by it.
pub fn router(self, router: Router<State>) -> Self
[src]
Attach a Router
.
pub fn with_state(self) -> StateRoute<'a, State>
[src]
Continue using stateful middleware and handlers.
Example
use hreq::prelude::*; use std::sync::{Arc, Mutex}; #[derive(Clone)] struct MyState(Arc<Mutex<String>>); async fn start_server() { let state = MyState(Arc::new(Mutex::new("Hello".to_string()))); let mut server = Server::with_state(state); server.at("/stateful").with_state().get(get_thing); } async fn get_thing(state: MyState, req: http::Request<Body>) -> String { format!("Hello {}", req.path_param("name").unwrap()) }
impl<'a, State> Route<'a, State> where
State: Clone + Unpin + Send + Sync + 'static,
[src]
State: Clone + Unpin + Send + Sync + 'static,
pub fn method<H: Handler>(self, method: Method, handler: H) -> Self
[src]
Attach a handler for the given method.
pub fn all<H: Handler>(self, handler: H) -> Self
[src]
Attach a handler for all methods.
pub fn get<H: Handler>(self, handler: H) -> Self
[src]
GET request handler.
pub fn head<H: Handler>(self, handler: H) -> Self
[src]
HEAD request handler.
pub fn post<H: Handler>(self, handler: H) -> Self
[src]
POST request handler.
pub fn put<H: Handler>(self, handler: H) -> Self
[src]
PUT request handler.
pub fn delete<H: Handler>(self, handler: H) -> Self
[src]
DELETE request handler.
pub fn options<H: Handler>(self, handler: H) -> Self
[src]
OPTIONS request handler.
pub fn connect<H: Handler>(self, handler: H) -> Self
[src]
CONNECT request handler.
pub fn patch<H: Handler>(self, handler: H) -> Self
[src]
PATCH request handler.
pub fn trace<H: Handler>(self, handler: H) -> Self
[src]
TRACE request handler.
Trait Implementations
Auto Trait Implementations
impl<'a, State> !RefUnwindSafe for Route<'a, State>
impl<'a, State> Send for Route<'a, State>
impl<'a, State> Sync for Route<'a, State>
impl<'a, State> Unpin for Route<'a, State>
impl<'a, State> !UnwindSafe for Route<'a, 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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub 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, 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.
pub 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>,