Struct hreq::server::Route[][src]

pub struct Route<'a, State> { /* fields omitted */ }

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]

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]

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

impl<'a, State> Debug for Route<'a, State>[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.