Struct ntex::web::Route [−][src]
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]
pub fn method(mut self: 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>(mut self: 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>(mut self: 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]
F: Handler<Args, Err>,
Args: FromRequest<Err> + 'static,
Args::Error: Into<Err::Container>,
<F::Output as Responder<Err>>::Error: Into<Err::Container>,
Set handler function, use request extractors for parameters.
use ntex::web; use serde_derive::Deserialize; #[derive(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(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> ServiceFactory for Route<Err>
[src]
type Config = ()
Service factory configuration
type Request = WebRequest<Err>
Requests handled by the service.
type Response = WebResponse
Responses given by the service
type Error = Err::Container
Errors produced by the service
type InitError = ()
Errors produced while building a service.
type Service = RouteService<Err>
The Service
value created by this factory
type Future = Ready<Result<RouteService<Err>, ()>>
The future of the ServiceFactory
instance.
fn new_service(&self, _: ()) -> Self::Future
[src]
pub fn map<F, R>(self, f: F) -> MapServiceFactory<Self, F, R> where
F: FnMut(Self::Response) -> R + Clone,
[src]
F: FnMut(Self::Response) -> R + Clone,
pub fn map_err<F, E>(self, f: F) -> MapErrServiceFactory<Self, F, E> where
F: Fn(Self::Error) -> E + Clone,
[src]
F: Fn(Self::Error) -> E + Clone,
pub fn map_init_err<F, E>(self, f: F) -> MapInitErr<Self, F, E> where
F: Fn(Self::InitError) -> E + Clone,
[src]
F: Fn(Self::InitError) -> E + Clone,
Auto Trait Implementations
impl<Err = DefaultError> !RefUnwindSafe for Route<Err>
[src]
impl<Err = DefaultError> !Send for Route<Err>
[src]
impl<Err = DefaultError> !Sync for Route<Err>
[src]
impl<Err> Unpin for Route<Err>
[src]
impl<Err = DefaultError> !UnwindSafe for Route<Err>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoServiceFactory<T> for T where
T: ServiceFactory,
[src]
T: ServiceFactory,
pub fn into_factory(self) -> T
[src]
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,