[−][src]Struct actix_web::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 Route
[src]
impl Route
[src]
pub fn method(self, method: Method) -> Self
[src]
Add method guard to the route.
App::new().service(web::resource("/path").route( web::get() .method(http::Method::CONNECT) .guard(guard::Header("content-type", "text/plain")) .to(|req: HttpRequest| HttpResponse::Ok())) );
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| HttpResponse::Ok())) );
pub fn to<F, T, R, U>(self, handler: F) -> Self where
F: Factory<T, R, U>,
T: FromRequest + 'static,
R: Future<Output = U> + 'static,
U: Responder + 'static,
[src]
F: Factory<T, R, U>,
T: FromRequest + 'static,
R: Future<Output = U> + 'static,
U: Responder + 'static,
Set handler function, use request extractors for parameters.
use actix_web::{web, http, App}; use serde_derive::Deserialize; #[derive(Deserialize)] struct Info { username: String, } /// extract path info using serde async fn index(info: web::Path<Info>) -> String { format!("Welcome {}!", info.username) } fn main() { let app = 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 actix_web::{web, App}; #[derive(Deserialize)] struct Info { username: String, } /// extract path info using serde async fn index(path: web::Path<Info>, query: web::Query<HashMap<String, String>>, body: web::Json<Info>) -> String { format!("Welcome {}!", path.username) } fn main() { let app = App::new().service( web::resource("/{username}/index.html") // <- define path parameters .route(web::get().to(index)) ); }
Trait Implementations
impl ServiceFactory for Route
[src]
type Config = ()
Service factory configuration
type Request = ServiceRequest
Requests handled by the service.
type Response = ServiceResponse
Responses given by the service
type Error = Error
Errors produced by the service
type InitError = ()
Errors produced while building a service.
type Service = RouteService
The Service
value created by this factory
type Future = CreateRouteService
The future of the Service
instance.
fn new_service(&self, _: ()) -> Self::Future
[src]
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,
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,
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 !RefUnwindSafe for Route
impl !Send for Route
impl !Sync for Route
impl Unpin for Route
impl !UnwindSafe for Route
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[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,
fn into_factory(self) -> T
[src]
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.
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.
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>,