Struct actix_web::dev::Route
[−]
[src]
pub struct Route<S> { /* fields omitted */ }
Resource route definition
Route uses builder-like pattern for configuration. If handler is not explicitly set, default 404 Not Found handler is used.
Methods
impl<S: 'static> Route<S>
[src]
ⓘImportant traits for &'a mut Wpub fn filter<T: Predicate<S> + 'static>(&mut self, p: T) -> &mut Self
[src]
ⓘImportant traits for &'a mut W
Add match predicate to route.
App::new() .resource("/path", |r| r.route() .filter(pred::Get()) .filter(pred::Header("content-type", "text/plain")) .f(|req| HttpResponse::Ok()) )
pub fn h<H: Handler<S>>(&mut self, handler: H)
[src]
Set handler object. Usually call to this method is last call during route configuration, so it does not return reference to self.
pub fn f<F, R>(&mut self, handler: F) where
F: Fn(HttpRequest<S>) -> R + 'static,
R: Responder + 'static,
[src]
F: Fn(HttpRequest<S>) -> R + 'static,
R: Responder + 'static,
Set handler function. Usually call to this method is last call during route configuration, so it does not return reference to self.
pub fn a<H, R, F, E>(&mut self, handler: H) where
H: Fn(HttpRequest<S>) -> F + 'static,
F: Future<Item = R, Error = E> + 'static,
R: Responder + 'static,
E: Into<Error> + 'static,
[src]
H: Fn(HttpRequest<S>) -> F + 'static,
F: Future<Item = R, Error = E> + 'static,
R: Responder + 'static,
E: Into<Error> + 'static,
Set async handler function.
pub fn with<T, F, R>(&mut self, handler: F) -> ExtractorConfig<S, T> where
F: Fn(T) -> R + 'static,
R: Responder + 'static,
T: FromRequest<S> + 'static,
[src]
F: Fn(T) -> R + 'static,
R: Responder + 'static,
T: FromRequest<S> + 'static,
Set handler function, use request extractor for parameters.
#[macro_use] extern crate serde_derive; use actix_web::{App, Path, Result, http}; #[derive(Deserialize)] struct Info { username: String, } /// extract path info using serde fn index(info: Path<Info>) -> Result<String> { Ok(format!("Welcome {}!", info.username)) } fn main() { let app = App::new().resource( "/{username}/index.html", // <- define path parameters |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor }
pub fn with2<T1, T2, F, R>(
&mut self,
handler: F
) -> (ExtractorConfig<S, T1>, ExtractorConfig<S, T2>) where
F: Fn(T1, T2) -> R + 'static,
R: Responder + 'static,
T1: FromRequest<S> + 'static,
T2: FromRequest<S> + 'static,
[src]
&mut self,
handler: F
) -> (ExtractorConfig<S, T1>, ExtractorConfig<S, T2>) where
F: Fn(T1, T2) -> R + 'static,
R: Responder + 'static,
T1: FromRequest<S> + 'static,
T2: FromRequest<S> + 'static,
Set handler function, use request extractor for both parameters.
#[macro_use] extern crate serde_derive; use actix_web::{App, Query, Path, Result, http}; #[derive(Deserialize)] struct PParam { username: String, } #[derive(Deserialize)] struct QParam { count: u32, } /// extract path and query information using serde fn index(p: Path<PParam>, q: Query<QParam>) -> Result<String> { Ok(format!("Welcome {}!", p.username)) } fn main() { let app = App::new().resource( "/{username}/index.html", // <- define path parameters |r| r.method(http::Method::GET).with2(index)); // <- use `with` extractor }
pub fn with3<T1, T2, T3, F, R>(
&mut self,
handler: F
) -> (ExtractorConfig<S, T1>, ExtractorConfig<S, T2>, ExtractorConfig<S, T3>) where
F: Fn(T1, T2, T3) -> R + 'static,
R: Responder + 'static,
T1: FromRequest<S> + 'static,
T2: FromRequest<S> + 'static,
T3: FromRequest<S> + 'static,
[src]
&mut self,
handler: F
) -> (ExtractorConfig<S, T1>, ExtractorConfig<S, T2>, ExtractorConfig<S, T3>) where
F: Fn(T1, T2, T3) -> R + 'static,
R: Responder + 'static,
T1: FromRequest<S> + 'static,
T2: FromRequest<S> + 'static,
T3: FromRequest<S> + 'static,
Set handler function, use request extractor for all parameters.