mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-31 02:52:53 +01:00
Improve the documentation for default_service
(#2614)
This commit is contained in:
parent
21a08ca796
commit
a3416112a5
17
src/app.rs
17
src/app.rs
@ -236,9 +236,9 @@ where
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default service to be used if no matching resource could be found.
|
/// Default service that is invoked when no matching resource could be found.
|
||||||
///
|
///
|
||||||
/// It is possible to use services like `Resource`, `Route`.
|
/// You must use a [`Route`] as default service:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::{web, App, HttpResponse};
|
/// use actix_web::{web, App, HttpResponse};
|
||||||
@ -253,19 +253,6 @@ where
|
|||||||
/// .default_service(
|
/// .default_service(
|
||||||
/// web::route().to(|| HttpResponse::NotFound()));
|
/// web::route().to(|| HttpResponse::NotFound()));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// It is also possible to use static files as default service.
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use actix_web::{web, App, HttpResponse};
|
|
||||||
///
|
|
||||||
/// let app = App::new()
|
|
||||||
/// .service(
|
|
||||||
/// web::resource("/index.html").to(|| HttpResponse::Ok()))
|
|
||||||
/// .default_service(
|
|
||||||
/// web::to(|| HttpResponse::NotFound())
|
|
||||||
/// );
|
|
||||||
/// ```
|
|
||||||
pub fn default_service<F, U>(mut self, svc: F) -> Self
|
pub fn default_service<F, U>(mut self, svc: F) -> Self
|
||||||
where
|
where
|
||||||
F: IntoServiceFactory<U, ServiceRequest>,
|
F: IntoServiceFactory<U, ServiceRequest>,
|
||||||
|
@ -313,8 +313,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Default service to be used if no matching route could be found.
|
/// Default service to be used if no matching route could be found.
|
||||||
/// By default *405* response get returned. Resource does not use
|
/// You can pass a [`Route`] as default_service.
|
||||||
/// default handler from `App` or `Scope`.
|
///
|
||||||
|
/// If no default service is specified, a `405 Method Not Allowed` response will be returned to the caller.
|
||||||
|
/// [`Resource`] does **not** inherit the default handler specified on the parent [`App`](crate::App) or [`Scope`](crate::Scope).
|
||||||
pub fn default_service<F, U>(mut self, f: F) -> Self
|
pub fn default_service<F, U>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: IntoServiceFactory<U, ServiceRequest>,
|
F: IntoServiceFactory<U, ServiceRequest>,
|
||||||
|
@ -264,7 +264,8 @@ where
|
|||||||
|
|
||||||
/// Default service to be used if no matching route could be found.
|
/// Default service to be used if no matching route could be found.
|
||||||
///
|
///
|
||||||
/// If default resource is not registered, app's default resource is being used.
|
/// If a default service is not registered, it will fall back to the default service of
|
||||||
|
/// the parent [`App`](crate::App) (see [`App::default_service`](crate::App::default_service).
|
||||||
pub fn default_service<F, U>(mut self, f: F) -> Self
|
pub fn default_service<F, U>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: IntoServiceFactory<U, ServiceRequest>,
|
F: IntoServiceFactory<U, ServiceRequest>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user