[−][src]Struct actix_web::dev::Route
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]
impl<S: 'static> Route<S>
pub fn filter<T: Predicate<S> + 'static>(&mut self, p: T) -> &mut Self
[src]
pub fn filter<T: Predicate<S> + 'static>(&mut self, p: T) -> &mut Self
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]
pub fn h<H: Handler<S>>(&mut self, handler: H)
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]
pub fn f<F, R>(&mut self, handler: F) where
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]
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,
Set async handler function.
pub fn with<T, F, R>(&mut self, handler: F) where
F: WithFactory<T, S, R> + 'static,
R: Responder + 'static,
T: FromRequest<S> + 'static,
[src]
pub fn with<T, F, R>(&mut self, handler: F) where
F: WithFactory<T, S, 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::{http, App, Path, Result}; #[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 }
It is possible to use multiple extractors for one handler function.
#[macro_use] extern crate serde_derive; use actix_web::{http, App, Json, Path, Query, Result}; #[derive(Deserialize)] struct Info { username: String, } /// extract path info using serde fn index( path: Path<Info>, query: Query<HashMap<String, String>>, body: Json<Info>, ) -> Result<String> { Ok(format!("Welcome {}!", path.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 with_config<T, F, R, C>(&mut self, handler: F, cfg_f: C) where
F: WithFactory<T, S, R>,
R: Responder + 'static,
T: FromRequest<S> + 'static,
C: FnOnce(&mut T::Config),
[src]
pub fn with_config<T, F, R, C>(&mut self, handler: F, cfg_f: C) where
F: WithFactory<T, S, R>,
R: Responder + 'static,
T: FromRequest<S> + 'static,
C: FnOnce(&mut T::Config),
Set handler function. Same as .with()
but it allows to configure
extractor. Configuration closure accepts config objects as tuple.
#[macro_use] extern crate serde_derive; use actix_web::{http, App, Path, Result}; /// extract text data from request fn index(body: String) -> Result<String> { Ok(format!("Body {}!", body)) } fn main() { let app = App::new().resource("/index.html", |r| { r.method(http::Method::GET) .with_config(index, |cfg| { // <- register handler cfg.0.limit(4096); // <- limit size of the payload }) }); }
pub fn with_async<T, F, R, I, E>(&mut self, handler: F) where
F: WithAsyncFactory<T, S, R, I, E>,
R: Future<Item = I, Error = E> + 'static,
I: Responder + 'static,
E: Into<Error> + 'static,
T: FromRequest<S> + 'static,
[src]
pub fn with_async<T, F, R, I, E>(&mut self, handler: F) where
F: WithAsyncFactory<T, S, R, I, E>,
R: Future<Item = I, Error = E> + 'static,
I: Responder + 'static,
E: Into<Error> + 'static,
T: FromRequest<S> + 'static,
Set async handler function, use request extractor for parameters.
Also this method needs to be used if your handler function returns
impl Future<>
#[macro_use] extern crate serde_derive; use actix_web::{http, App, Error, Path}; use futures::Future; #[derive(Deserialize)] struct Info { username: String, } /// extract path info using serde fn index(info: Path<Info>) -> Box<Future<Item = &'static str, Error = Error>> { unimplemented!() } fn main() { let app = App::new().resource( "/{username}/index.html", // <- define path parameters |r| r.method(http::Method::GET).with_async(index), ); // <- use `with` extractor }
pub fn with_async_config<T, F, R, I, E, C>(&mut self, handler: F, cfg: C) where
F: WithAsyncFactory<T, S, R, I, E>,
R: Future<Item = I, Error = E> + 'static,
I: Responder + 'static,
E: Into<Error> + 'static,
T: FromRequest<S> + 'static,
C: FnOnce(&mut T::Config),
[src]
pub fn with_async_config<T, F, R, I, E, C>(&mut self, handler: F, cfg: C) where
F: WithAsyncFactory<T, S, R, I, E>,
R: Future<Item = I, Error = E> + 'static,
I: Responder + 'static,
E: Into<Error> + 'static,
T: FromRequest<S> + 'static,
C: FnOnce(&mut T::Config),
Set async handler function, use request extractor for parameters. This method allows to configure extractor. Configuration closure accepts config objects as tuple.
#[macro_use] extern crate serde_derive; use actix_web::{http, App, Error, Form}; use futures::Future; #[derive(Deserialize)] struct Info { username: String, } /// extract path info using serde fn index(info: Form<Info>) -> Box<Future<Item = &'static str, Error = Error>> { unimplemented!() } fn main() { let app = App::new().resource( "/{username}/index.html", // <- define path parameters |r| r.method(http::Method::GET) .with_async_config(index, |cfg| { cfg.0.limit(4096); }), ); // <- use `with` extractor }
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Erased for T
impl<T> Erased for T