pub struct ServiceConfig<St, In = ()> { /* private fields */ }Expand description
Service config is used for external configuration.
Part of application configuration could be offloaded to set of external methods. This could help with modularization of big application configuration.
Implementations§
Source§impl<St: State, In: 'static> ServiceConfig<St, In>
impl<St: State, In: 'static> ServiceConfig<St, In>
Sourcepub fn new(external: Vec<ResourceDef>) -> Self
pub fn new(external: Vec<ResourceDef>) -> Self
Create a service configuration with the given external resources.
Sourcepub fn route(&mut self, path: &str, route: Route<St, In>) -> &mut Self
pub fn route(&mut self, path: &str, route: Route<St, In>) -> &mut Self
Register a route for an application path.
This has the same behavior as App::route(): it creates a separate
resource containing the route and promotes the route’s method and custom
guards to resource guards.
Sourcepub fn service<F>(&mut self, factory: F) -> &mut Selfwhere
F: WebServiceFactory<St, In> + 'static,
pub fn service<F>(&mut self, factory: F) -> &mut Selfwhere
F: WebServiceFactory<St, In> + 'static,
Registers a web service with the current application or scope.
This has the same routing behavior as App::service(). The service
can be a resource, scope, attribute-macro handler, or custom
WebServiceFactory. When this configuration is used by a scope, the
service is registered below that scope’s path prefix.
use ntex::web::{self, App, ServiceConfig};
fn configure(cfg: &mut ServiceConfig<()>) {
cfg.service(
web::resource("/health").to(async || "OK"),
);
}
App::default().configure(configure);Sourcepub fn external_resource(
&mut self,
name: impl AsRef<str>,
url: impl AsRef<str>,
) -> &mut Self
pub fn external_resource( &mut self, name: impl AsRef<str>, url: impl AsRef<str>, ) -> &mut Self
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.
This is same as App::external_resource() method.