Struct ServiceConfig
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§
§impl ServiceConfig
impl ServiceConfig
pub 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().
pub 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().
pub fn default_service<F, U>(&mut self, f: F) -> &mut ServiceConfig
pub fn default_service<F, U>(&mut self, f: F) -> &mut ServiceConfig
Default service to be used if no matching resource could be found.
Counterpart to App::default_service().
pub 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.
pub 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().
pub 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().
pub 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 UnsafeUnpin 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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].