Skip to main content

ServiceConfig

Struct ServiceConfig 

Source
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>

Source

pub fn new(external: Vec<ResourceDef>) -> Self

Create a service configuration with the given external resources.

Source

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.

Source

pub fn service<F>(&mut self, factory: F) -> &mut Self
where 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);
Source

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.

Trait Implementations§

Source§

impl<St, In> Debug for ServiceConfig<St, In>

Source§

fn fmt(&self, __derive_more_f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<St, In = ()> !RefUnwindSafe for ServiceConfig<St, In>

§

impl<St, In = ()> !Send for ServiceConfig<St, In>

§

impl<St, In = ()> !Sync for ServiceConfig<St, In>

§

impl<St, In = ()> !UnwindSafe for ServiceConfig<St, In>

§

impl<St, In> Freeze for ServiceConfig<St, In>

§

impl<St, In> Unpin for ServiceConfig<St, In>

§

impl<St, In> UnsafeUnpin for ServiceConfig<St, In>

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.