Struct actix_web::Resource
[−]
[src]
pub struct Resource<S = ()> { /* fields omitted */ }
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::*; fn main() { let app = Application::new() .resource( "/", |r| r.method(Method::GET).f(|r| HttpResponse::Ok())) .finish(); }
Methods
impl<S> Resource<S>
[src]
impl<S: 'static> Resource<S>
[src]
fn route(&mut self) -> &mut Route<S>
[src]
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 = Application::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(); }
fn method(&mut self, method: Method) -> &mut Route<S>
[src]
Register a new route and add method check to route.
This is shortcut for:
Resource::resource("/", |r| r.route().filter(pred::Get()).f(index)
fn h<H: Handler<S>>(&mut self, handler: H)
[src]
Register a new route and add handler object.
This is shortcut for:
Resource::resource("/", |r| r.route().h(handler)
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,
Register a new route and add handler function.
This is shortcut for:
Resource::resource("/", |r| r.route().f(index)
fn middleware<M: Middleware<S>>(&mut self, mw: M)
[src]
Register a middleware
This is similar to Application's
middlewares, but
middlewares get invoked on resource level.