pub struct ServiceConfig { /* private fields */ }
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);

Implementations§

source§

impl ServiceConfig

source

pub fn data<U: 'static>(&mut self, data: U) -> &mut Self

👎Deprecated since 4.0.0: Use .app_data(Data::new(val)) instead.

Add shared app data item.

Counterpart to App::data().

source

pub fn app_data<U: 'static>(&mut self, ext: U) -> &mut Self

Add arbitrary app data item.

Counterpart to App::app_data().

source

pub fn default_service<F, U>(&mut self, f: F) -> &mut Self
where F: IntoServiceFactory<U, ServiceRequest>, U: ServiceFactory<ServiceRequest, Config = (), Response = ServiceResponse, Error = Error> + 'static, U::InitError: Debug,

Default service to be used if no matching resource could be found.

Counterpart to App::default_service().

source

pub fn configure<F>(&mut self, f: F) -> &mut Self
where F: FnOnce(&mut ServiceConfig),

Run external configuration as part of the application building process

Counterpart to App::configure() that allows for easy nesting.

source

pub fn route(&mut self, path: &str, route: Route) -> &mut Self

Configure route for a specific path.

Counterpart to App::route().

source

pub fn service<F>(&mut self, factory: F) -> &mut Self
where F: HttpServiceFactory + 'static,

Register HTTP service factory.

Counterpart to App::service().

source

pub fn external_resource<N, U>(&mut self, name: N, url: U) -> &mut Self
where N: AsRef<str>, U: AsRef<str>,

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§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more