[−][src]Struct actix_web::dev::AppRouter
Application router builder - Structure that follows the builder pattern for building application instances.
Methods
impl<C, P, B, T> AppRouter<C, P, B, T> where
P: 'static,
B: MessageBody,
T: NewService<Request = ServiceRequest<P>, Response = ServiceResponse<B>, Error = Error, InitError = ()>,
[src]
P: 'static,
B: MessageBody,
T: NewService<Request = ServiceRequest<P>, Response = ServiceResponse<B>, Error = Error, InitError = ()>,
pub fn route(self, path: &str, route: Route<P>) -> Self
[src]
Configure route for a specific path.
This is a simplified version of the App::service()
method.
This method can not be could multiple times, in that case
multiple resources with one route would be registered for same resource path.
use actix_web::{web, App, HttpResponse}; fn index(data: web::Path<(String, String)>) -> &'static str { "Welcome!" } fn main() { let app = App::new() .route("/test1", web::get().to(index)) .route("/test2", web::post().to(|| HttpResponse::MethodNotAllowed())); }
pub fn service<F>(self, factory: F) -> Self where
F: HttpServiceFactory<P> + 'static,
[src]
F: HttpServiceFactory<P> + 'static,
Register http service.
Http service is any type that implements HttpServiceFactory
trait.
Actix web provides several services implementations:
- Resource is an entry in resource table which corresponds to requested URL.
- Scope is a set of resources with common root path.
- "StaticFiles" is a service for static files support
pub fn wrap<M, B1, F>(
self,
mw: F
) -> AppRouter<C, P, B1, impl NewService<Request = ServiceRequest<P>, Response = ServiceResponse<B1>, Error = Error, InitError = ()>> where
M: Transform<T::Service, Request = ServiceRequest<P>, Response = ServiceResponse<B1>, Error = Error, InitError = ()>,
B1: MessageBody,
F: IntoTransform<M, T::Service>,
[src]
self,
mw: F
) -> AppRouter<C, P, B1, impl NewService<Request = ServiceRequest<P>, Response = ServiceResponse<B1>, Error = Error, InitError = ()>> where
M: Transform<T::Service, Request = ServiceRequest<P>, Response = ServiceResponse<B1>, Error = Error, InitError = ()>,
B1: MessageBody,
F: IntoTransform<M, T::Service>,
Register a middleware.
pub fn wrap_fn<B1, F, R>(
self,
mw: F
) -> AppRouter<C, P, B1, impl NewService<Request = ServiceRequest<P>, Response = ServiceResponse<B1>, Error = Error, InitError = ()>> where
B1: MessageBody,
F: FnMut(ServiceRequest<P>, &mut T::Service) -> R + Clone,
R: IntoFuture<Item = ServiceResponse<B1>, Error = Error>,
[src]
self,
mw: F
) -> AppRouter<C, P, B1, impl NewService<Request = ServiceRequest<P>, Response = ServiceResponse<B1>, Error = Error, InitError = ()>> where
B1: MessageBody,
F: FnMut(ServiceRequest<P>, &mut T::Service) -> R + Clone,
R: IntoFuture<Item = ServiceResponse<B1>, Error = Error>,
Register a middleware function.
pub fn default_resource<F, U>(self, f: F) -> Self where
F: FnOnce(Resource<P>) -> Resource<P, U>,
U: NewService<Request = ServiceRequest<P>, Response = ServiceResponse, Error = Error, InitError = ()> + 'static,
[src]
F: FnOnce(Resource<P>) -> Resource<P, U>,
U: NewService<Request = ServiceRequest<P>, Response = ServiceResponse, Error = Error, InitError = ()> + 'static,
Default resource to be used if no matching resource could be found.
pub fn external_resource<N, U>(self, name: N, url: U) -> Self where
N: AsRef<str>,
U: AsRef<str>,
[src]
N: AsRef<str>,
U: AsRef<str>,
Register an external resource.
External resources are useful for URL generation purposes only
and are never considered for matching at request time. Calls to
HttpRequest::url_for()
will work as expected.
use actix_web::{web, App, HttpRequest, HttpResponse, Result}; fn index(req: HttpRequest) -> Result<HttpResponse> { let url = req.url_for("youtube", &["asdlkjqme"])?; assert_eq!(url.as_str(), "https://youtube.com/watch/asdlkjqme"); Ok(HttpResponse::Ok().into()) } fn main() { let app = App::new() .service(web::resource("/index.html").route( web::get().to(index))) .external_resource("youtube", "https://youtube.com/watch/{video_id}"); }
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom 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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto 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.