mirror of
https://github.com/actix/actix-web.git
synced 2024-12-24 00:50:36 +00:00
tweak default_service docs
This commit is contained in:
parent
a3416112a5
commit
b3e84b5c4b
4 changed files with 16 additions and 12 deletions
12
src/app.rs
12
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<F, U>(mut self, svc: F) -> Self
|
||||
where
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<F, U>(mut self, f: F) -> Self
|
||||
where
|
||||
F: IntoServiceFactory<U, ServiceRequest>,
|
||||
|
|
|
@ -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<F, U>(mut self, f: F) -> Self
|
||||
where
|
||||
F: IntoServiceFactory<U, ServiceRequest>,
|
||||
|
|
Loading…
Reference in a new issue