mirror of https://github.com/fafhrd91/actix-web
improve docs
This commit is contained in:
parent
8ca6e168f2
commit
2b70a7e8e8
|
@ -41,8 +41,8 @@ use crate::{
|
||||||
/// .route(web::get().to(|| HttpResponse::Ok())));
|
/// .route(web::get().to(|| HttpResponse::Ok())));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// If no matching route could be found, *405* response code get returned. Default behavior could be
|
/// If no matching route is found, a 405 response is returned with an appropriate Allow header.
|
||||||
/// overridden with `default_resource()` method.
|
/// This default behavior can be overridden using [`default_service()`](Self::default_service).
|
||||||
pub struct Resource<T = ResourceEndpoint> {
|
pub struct Resource<T = ResourceEndpoint> {
|
||||||
endpoint: T,
|
endpoint: T,
|
||||||
rdef: Patterns,
|
rdef: Patterns,
|
||||||
|
@ -322,13 +322,28 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Default service to be used if no matching route could be found.
|
/// Sets the default service to be used if no matching route is found.
|
||||||
///
|
///
|
||||||
/// You can use a [`Route`] as default service.
|
/// Unlike [`Scope`]s, a `Resource` does _not_ inherit its parent's default service. You can
|
||||||
|
/// use a [`Route`] as default service.
|
||||||
///
|
///
|
||||||
/// If a default service is not registered, an empty `405 Method Not Allowed` response will be
|
/// If a custom default service is not registered, an empty `405 Method Not Allowed` response
|
||||||
/// sent to the client instead. Unlike [`Scope`](crate::Scope)s, a [`Resource`] does **not**
|
/// with an appropriate Allow header will be sent instead.
|
||||||
/// inherit its parent's default service.
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```
|
||||||
|
/// use actix_web::{App, HttpResponse, web};
|
||||||
|
///
|
||||||
|
/// let resource = web::resource("/test")
|
||||||
|
/// .route(web::get().to(HttpResponse::Ok))
|
||||||
|
/// .default_service(web::to(|| {
|
||||||
|
/// HttpResponse::BadRequest()
|
||||||
|
/// }));
|
||||||
|
///
|
||||||
|
/// App::new().service(resource);
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`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>,
|
||||||
|
|
Loading…
Reference in New Issue