logo
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

👎 Deprecated since 4.0.0:

Use .app_data(Data::new(val)) instead.

Add shared app data item.

Counterpart to App::data().

Add arbitrary app data item.

Counterpart to App::app_data().

Run external configuration as part of the application building process

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

Configure route for a specific path.

Counterpart to App::route().

Register HTTP service factory.

Counterpart to App::service().

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

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

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

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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