diff --git a/src/app.rs b/src/app.rs index bbf752595..a63cf5d50 100644 --- a/src/app.rs +++ b/src/app.rs @@ -238,8 +238,12 @@ where /// Default service that is invoked when no matching resource could be found. /// - /// You must use a [`Route`] as default service: + /// You can use a [`Route`] as default service. /// + /// If a default service is not registered, an empty `404 Not Found` response will be sent to + /// the client instead. + /// + /// # Examples /// ``` /// use actix_web::{web, App, HttpResponse}; /// @@ -248,10 +252,8 @@ where /// } /// /// let app = App::new() - /// .service( - /// web::resource("/index.html").route(web::get().to(index))) - /// .default_service( - /// web::route().to(|| HttpResponse::NotFound())); + /// .service(web::resource("/index.html").route(web::get().to(index))) + /// .default_service(web::to(|| HttpResponse::NotFound())); /// ``` pub fn default_service(mut self, svc: F) -> Self where diff --git a/src/app_service.rs b/src/app_service.rs index edfb3e4a2..dbd718330 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -72,7 +72,7 @@ where }))) }); - // App config + // create App config to pass to child services let mut config = AppService::new(config, default.clone()); // register services diff --git a/src/resource.rs b/src/resource.rs index 3451eff45..6a01a0496 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -312,11 +312,13 @@ where } } - /// Default service to be used if no matching route could be found. - /// You can pass a [`Route`] as default_service. + /// Default service to be used if no matching route could be found. /// - /// 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). + /// You can use a [`Route`] as default service. + /// + /// If a default service is not registered, an empty `405 Method Not Allowed` response will be + /// sent to the client instead. Unlike [`Scope`](crate::Scope)s, a [`Resource`] does **not** + /// inherit its parent's default service. pub fn default_service(mut self, f: F) -> Self where F: IntoServiceFactory, diff --git a/src/scope.rs b/src/scope.rs index 0bad5c581..dad727430 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -262,10 +262,10 @@ where ) } - /// Default service to be used if no matching route could be found. + /// Default service to be used if no matching resource could be found. /// /// 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). + /// the parent [`App`](crate::App) (see [`App::default_service`](crate::App::default_service)). pub fn default_service(mut self, f: F) -> Self where F: IntoServiceFactory,