Struct ntex::web::Route [−][src]
pub struct Route<Err: ErrorRenderer = DefaultError> { /* fields omitted */ }
Expand description
Resource route definition
Route uses builder-like pattern for configuration. If handler is not explicitly set, default 404 Not Found handler is used.
Implementations
impl<Err: ErrorRenderer> Route<Err>
[src]
impl<Err: ErrorRenderer> Route<Err>
[src]impl<Err: ErrorRenderer> Route<Err>
[src]
impl<Err: ErrorRenderer> Route<Err>
[src]pub fn method(self, method: Method) -> Self
[src]
pub fn method(self, method: Method) -> Self
[src]Add method guard to the route.
App::new().service(web::resource("/path").route( web::route() .method(http::Method::CONNECT) .guard(guard::Header("content-type", "text/plain")) .to(|req: HttpRequest| async { HttpResponse::Ok() })) );
pub fn guard<F: Guard + 'static>(self, f: F) -> Self
[src]
pub fn guard<F: Guard + 'static>(self, f: F) -> Self
[src]Add guard to the route.
App::new().service(web::resource("/path").route( web::route() .guard(guard::Get()) .guard(guard::Header("content-type", "text/plain")) .to(|req: HttpRequest| async { HttpResponse::Ok() })) );
pub fn to<F, Args>(self, handler: F) -> Self where
F: Handler<Args, Err>,
Args: FromRequest<Err> + 'static,
Args::Error: Into<Err::Container>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
[src]
pub fn to<F, Args>(self, handler: F) -> Self where
F: Handler<Args, Err>,
Args: FromRequest<Err> + 'static,
Args::Error: Into<Err::Container>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
[src]Set handler function, use request extractors for parameters.
use ntex::web; #[derive(serde::Deserialize)] struct Info { username: String, } /// extract path info using serde async fn index(info: web::types::Path<Info>) -> String { format!("Welcome {}!", info.username) } fn main() { let app = web::App::new().service( web::resource("/{username}/index.html") // <- define path parameters .route(web::get().to(index)) // <- register handler ); }
It is possible to use multiple extractors for one handler function.
use ntex::web; #[derive(serde::Deserialize)] struct Info { username: String, } /// extract path info using serde async fn index(path: web::types::Path<Info>, query: web::types::Query<HashMap<String, String>>, body: web::types::Json<Info>) -> String { format!("Welcome {}!", path.username) } fn main() { let app = web::App::new().service( web::resource("/{username}/index.html") // <- define path parameters .route(web::get().to(index)) ); }
Trait Implementations
impl<Err: ErrorRenderer> IntoRoutes<Err> for Route<Err>
[src]
impl<Err: ErrorRenderer> IntoRoutes<Err> for Route<Err>
[src]impl<Err: ErrorRenderer> ServiceFactory for Route<Err>
[src]
impl<Err: ErrorRenderer> ServiceFactory for Route<Err>
[src]type Request = WebRequest<Err>
type Request = WebRequest<Err>
Requests handled by the service.
type Response = WebResponse
type Response = WebResponse
Responses given by the service
type Service = RouteService<Err>
type Service = RouteService<Err>
The Service
value created by this factory
fn new_service(&self, _: ()) -> Self::Future
[src]
fn new_service(&self, _: ()) -> Self::Future
[src]Create and return a new service value asynchronously.
fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R> where
F: FnMut(Self::Response) -> R + Clone,
[src]
fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R> where
F: FnMut(Self::Response) -> R + Clone,
[src]Map this service’s output to a different type, returning a new service of the resulting type. Read more
fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E> where
F: Fn(Self::Error) -> E + Clone,
[src]
fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E> where
F: Fn(Self::Error) -> E + Clone,
[src]Map this service’s error to a different error, returning a new service.
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E> where
F: Fn(Self::InitError) -> E + Clone,
[src]
fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E> where
F: Fn(Self::InitError) -> E + Clone,
[src]Map this factory’s init error to a different error, returning a new service.
Auto Trait Implementations
impl<Err = DefaultError> !RefUnwindSafe for Route<Err>
impl<Err = DefaultError> !Send for Route<Err>
impl<Err = DefaultError> !Sync for Route<Err>
impl<Err> Unpin for Route<Err>
impl<Err = DefaultError> !UnwindSafe for Route<Err>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> IntoServiceFactory<T> for T where
T: ServiceFactory,
[src]
impl<T> IntoServiceFactory<T> for T where
T: ServiceFactory,
[src]pub fn into_factory(self) -> T
[src]
pub fn into_factory(self) -> T
[src]Convert Self
to a ServiceFactory
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self