[−][src]Struct actix_web::dev::Resource
Resource is an entry in route table which corresponds to requested URL.
Resource in turn has at least one route.
Route consists of an object that implements Handler
trait (handler)
and list of predicates (objects that implement Predicate
trait).
Route uses builder-like pattern for configuration.
During request handling, resource object iterate through all routes
and check all predicates for specific route, if request matches all
predicates route route considered matched and route handler get called.
use actix_web::{App, HttpResponse, http}; fn main() { let app = App::new() .resource( "/", |r| r.method(http::Method::GET).f(|r| HttpResponse::Ok())) .finish(); }
Methods
impl<S> Resource<S>
[src]
impl<S> Resource<S>
pub fn new(rdef: ResourceDef) -> Self
[src]
pub fn new(rdef: ResourceDef) -> Self
Create new resource with specified resource definition
pub fn name(&mut self, name: &str)
[src]
pub fn name(&mut self, name: &str)
Set resource name
pub fn rdef(&self) -> &ResourceDef
[src]
pub fn rdef(&self) -> &ResourceDef
Resource definition
impl<S: 'static> Resource<S>
[src]
impl<S: 'static> Resource<S>
pub fn route(&mut self) -> &mut Route<S>
[src]
pub fn route(&mut self) -> &mut Route<S>
Register a new route and return mutable reference to Route object. Route is used for route configuration, i.e. adding predicates, setting up handler.
use actix_web::*; fn main() { let app = App::new() .resource("/", |r| { r.route() .filter(pred::Any(pred::Get()).or(pred::Put())) .filter(pred::Header("Content-Type", "text/plain")) .f(|r| HttpResponse::Ok()) }) .finish(); }
pub fn get(&mut self) -> &mut Route<S>
[src]
pub fn get(&mut self) -> &mut Route<S>
Register a new GET
route.
pub fn post(&mut self) -> &mut Route<S>
[src]
pub fn post(&mut self) -> &mut Route<S>
Register a new POST
route.
pub fn put(&mut self) -> &mut Route<S>
[src]
pub fn put(&mut self) -> &mut Route<S>
Register a new PUT
route.
pub fn delete(&mut self) -> &mut Route<S>
[src]
pub fn delete(&mut self) -> &mut Route<S>
Register a new DELETE
route.
pub fn head(&mut self) -> &mut Route<S>
[src]
pub fn head(&mut self) -> &mut Route<S>
Register a new HEAD
route.
pub fn method(&mut self, method: Method) -> &mut Route<S>
[src]
pub fn method(&mut self, method: Method) -> &mut Route<S>
Register a new route and add method check to route.
use actix_web::*; fn index(req: &HttpRequest) -> HttpResponse { unimplemented!() } App::new().resource("/", |r| r.method(http::Method::GET).f(index));
This is shortcut for:
App::new().resource("/", |r| r.route().filter(pred::Get()).f(index));
pub fn h<H: Handler<S>>(&mut self, handler: H)
[src]
pub fn h<H: Handler<S>>(&mut self, handler: H)
Register a new route and add handler object.
use actix_web::*; fn handler(req: &HttpRequest) -> HttpResponse { unimplemented!() } App::new().resource("/", |r| r.h(handler));
This is shortcut for:
App::new().resource("/", |r| r.route().h(handler));
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,
Register a new route and add handler function.
use actix_web::*; fn index(req: &HttpRequest) -> HttpResponse { unimplemented!() } App::new().resource("/", |r| r.f(index));
This is shortcut for:
App::new().resource("/", |r| r.route().f(index));
pub fn with<T, F, R>(&mut self, handler: F) where
F: WithFactory<T, S, R>,
R: Responder + 'static,
T: FromRequest<S> + 'static,
[src]
pub fn with<T, F, R>(&mut self, handler: F) where
F: WithFactory<T, S, R>,
R: Responder + 'static,
T: FromRequest<S> + 'static,
Register a new route and add handler.
use actix_web::*; fn index(req: HttpRequest) -> HttpResponse { unimplemented!() } App::new().resource("/", |r| r.with(index));
This is shortcut for:
App::new().resource("/", |r| r.route().with(index));
pub fn with_async<T, F, R, I, E>(&mut self, handler: F) where
F: Fn(T) -> R + 'static,
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: Fn(T) -> R + 'static,
R: Future<Item = I, Error = E> + 'static,
I: Responder + 'static,
E: Into<Error> + 'static,
T: FromRequest<S> + 'static,
Register a new route and add async handler.
use actix_web::*; use futures::future::Future; fn index(req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> { unimplemented!() } App::new().resource("/", |r| r.with_async(index));
This is shortcut for:
App::new().resource("/", |r| r.route().with_async(index));
pub fn middleware<M: Middleware<S>>(&mut self, mw: M)
[src]
pub fn middleware<M: Middleware<S>>(&mut self, mw: M)
Register a resource middleware
This is similar to App's
middlewares, but
middlewares get invoked on resource level.
Note Middleware::finish()
fires right after response get
prepared. It does not wait until body get sent to peer.
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