pub struct ServiceConfig {
pub(crate) services: Vec<Box<dyn AppServiceFactory>>,
pub(crate) external: Vec<ResourceDef>,
pub(crate) app_data: Extensions,
pub(crate) default: Option<Rc<BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>>>,
}
Expand description
Enables parts of app configuration to be declared separately from the app itself. Helpful for modularizing large applications.
Merge a ServiceConfig
into an app using App::configure
. Scope and
resources services have similar methods.
use actix_web::{web, App, HttpResponse};
// this function could be located in different module
fn config(cfg: &mut web::ServiceConfig) {
cfg.service(web::resource("/test")
.route(web::get().to(|| HttpResponse::Ok()))
.route(web::head().to(|| HttpResponse::MethodNotAllowed()))
);
}
// merge `/test` routes from config function to App
App::new().configure(config);
Fields§
§services: Vec<Box<dyn AppServiceFactory>>
§external: Vec<ResourceDef>
§app_data: Extensions
§default: Option<Rc<BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>>>
Implementations§
Source§impl ServiceConfig
impl ServiceConfig
Sourcepub fn data<U>(&mut self, data: U) -> &mut ServiceConfigwhere
U: 'static,
👎Deprecated since 4.0.0: Use .app_data(Data::new(val))
instead.
pub fn data<U>(&mut self, data: U) -> &mut ServiceConfigwhere
U: 'static,
.app_data(Data::new(val))
instead.Add shared app data item.
Counterpart to App::data()
.
Sourcepub fn app_data<U>(&mut self, ext: U) -> &mut ServiceConfigwhere
U: 'static,
pub fn app_data<U>(&mut self, ext: U) -> &mut ServiceConfigwhere
U: 'static,
Add arbitrary app data item.
Counterpart to App::app_data()
.
Sourcepub fn default_service<F, U>(&mut self, f: F) -> &mut ServiceConfigwhere
F: IntoServiceFactory<U, ServiceRequest>,
U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static,
<U as ServiceFactory<ServiceRequest>>::InitError: Debug,
pub fn default_service<F, U>(&mut self, f: F) -> &mut ServiceConfigwhere
F: IntoServiceFactory<U, ServiceRequest>,
U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static,
<U as ServiceFactory<ServiceRequest>>::InitError: Debug,
Default service to be used if no matching resource could be found.
Counterpart to App::default_service()
.
Sourcepub fn configure<F>(&mut self, f: F) -> &mut ServiceConfigwhere
F: FnOnce(&mut ServiceConfig),
pub fn configure<F>(&mut self, f: F) -> &mut ServiceConfigwhere
F: FnOnce(&mut ServiceConfig),
Run external configuration as part of the application building process
Counterpart to App::configure()
that allows for easy nesting.
Sourcepub fn route(&mut self, path: &str, route: Route) -> &mut ServiceConfig
pub fn route(&mut self, path: &str, route: Route) -> &mut ServiceConfig
Configure route for a specific path.
Counterpart to App::route()
.
Sourcepub fn service<F>(&mut self, factory: F) -> &mut ServiceConfigwhere
F: HttpServiceFactory + 'static,
pub fn service<F>(&mut self, factory: F) -> &mut ServiceConfigwhere
F: HttpServiceFactory + 'static,
Register HTTP service factory.
Counterpart to App::service()
.
Sourcepub fn external_resource<N, U>(&mut self, name: N, url: U) -> &mut ServiceConfig
pub fn external_resource<N, U>(&mut self, name: N, url: U) -> &mut ServiceConfig
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.
Counterpart to App::external_resource()
.
Auto Trait Implementations§
impl Freeze for ServiceConfig
impl !RefUnwindSafe for ServiceConfig
impl !Send for ServiceConfig
impl !Sync for ServiceConfig
impl Unpin for ServiceConfig
impl !UnwindSafe for ServiceConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more