pub struct App { /* private fields */ }Expand description
A configured web application.
The App holds all routes, middleware, state, and lifecycle hooks,
and provides methods to handle incoming requests.
Implementations§
Source§impl App
impl App
Sourcepub fn builder() -> AppBuilder
pub fn builder() -> AppBuilder
Creates a new application builder.
Sourcepub fn test_client(self: Arc<Self>) -> TestClient<Arc<Self>>
pub fn test_client(self: Arc<Self>) -> TestClient<Arc<Self>>
Create an in-process test client for this app.
This takes Arc<Self> so tests can keep using shared Arc<App> values
without extra boilerplate.
Sourcepub fn test_client_with_seed(
self: Arc<Self>,
seed: u64,
) -> TestClient<Arc<Self>>
pub fn test_client_with_seed( self: Arc<Self>, seed: u64, ) -> TestClient<Arc<Self>>
Create an in-process test client with a deterministic seed.
Sourcepub fn route_count(&self) -> usize
pub fn route_count(&self) -> usize
Returns the number of registered routes.
Sourcepub fn websocket_route_count(&self) -> usize
pub fn websocket_route_count(&self) -> usize
Returns the number of registered websocket routes.
Sourcepub fn has_websocket_route(&self, path: &str) -> bool
pub fn has_websocket_route(&self, path: &str) -> bool
Returns true if a websocket route matches the given path.
Sourcepub fn routes(&self) -> impl Iterator<Item = (Method, &str)>
pub fn routes(&self) -> impl Iterator<Item = (Method, &str)>
Returns an iterator over route metadata (method, path).
This is useful for generating OpenAPI specifications or debugging.
Sourcepub fn openapi_spec(&self) -> Option<&str>
pub fn openapi_spec(&self) -> Option<&str>
Sourcepub fn state(&self) -> &Arc<StateContainer>
pub fn state(&self) -> &Arc<StateContainer>
Returns the shared state container.
Sourcepub fn get_state<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
pub fn get_state<T: Send + Sync + 'static>(&self) -> Option<Arc<T>>
Gets a reference to shared state of type T.
Sourcepub fn exception_handlers(&self) -> &Arc<ExceptionHandlers>
pub fn exception_handlers(&self) -> &Arc<ExceptionHandlers>
Returns the exception handlers registry.
Sourcepub fn override_dependency_value<T>(&self, value: T)where
T: FromDependency,
pub fn override_dependency_value<T>(&self, value: T)where
T: FromDependency,
Register a fixed override value for a dependency type.
This is a test-focused convenience API; production code typically wires
dependencies via crate::dependency::FromDependency implementations.
Sourcepub fn clear_dependency_overrides(&self)
pub fn clear_dependency_overrides(&self)
Clear all registered dependency overrides.
Sourcepub fn dependency_overrides(&self) -> Arc<DependencyOverrides>
pub fn dependency_overrides(&self) -> Arc<DependencyOverrides>
Returns the shared dependency overrides registry.
Sourcepub fn take_background_tasks(req: &mut Request) -> Option<BackgroundTasks>
pub fn take_background_tasks(req: &mut Request) -> Option<BackgroundTasks>
Take request-scoped background tasks (if any) from a request.
The HTTP server calls this after writing the response so any deferred work runs outside the main request handler path.
Sourcepub fn handle_error<E>(&self, ctx: &RequestContext, err: E) -> Option<Response>
pub fn handle_error<E>(&self, ctx: &RequestContext, err: E) -> Option<Response>
Handles an error using registered exception handlers.
If a handler is registered for the error type, it will be invoked.
Otherwise, returns None.
Sourcepub fn handle_error_or_default<E>(
&self,
ctx: &RequestContext,
err: E,
) -> Response
pub fn handle_error_or_default<E>( &self, ctx: &RequestContext, err: E, ) -> Response
Handles an error, returning a 500 response if no handler is registered.
Sourcepub async fn handle(&self, ctx: &RequestContext, req: &mut Request) -> Response
pub async fn handle(&self, ctx: &RequestContext, req: &mut Request) -> Response
Handles an incoming request.
This matches the request against registered routes, runs middleware, and returns the response.
Sourcepub async fn handle_websocket(
&self,
ctx: &RequestContext,
req: &mut Request,
ws: WebSocket,
) -> Result<(), WebSocketError>
pub async fn handle_websocket( &self, ctx: &RequestContext, req: &mut Request, ws: WebSocket, ) -> Result<(), WebSocketError>
Handles an incoming websocket upgrade request after the handshake has been accepted.
The HTTP server is responsible for validating the upgrade headers and writing the 101 response. This function only performs path matching and calls the websocket handler.
Sourcepub async fn run_startup_hooks(&self) -> StartupOutcome
pub async fn run_startup_hooks(&self) -> StartupOutcome
Runs all startup hooks.
Hooks run in registration order (FIFO). If a hook returns an error
with abort: true, execution stops and returns StartupOutcome::Aborted.
This consumes the startup hooks - they can only be run once.
§Returns
StartupOutcome::Successif all hooks succeededStartupOutcome::PartialSuccessif some hooks had non-fatal errorsStartupOutcome::Abortedif a fatal hook error occurred
Sourcepub async fn run_shutdown_hooks(&self)
pub async fn run_shutdown_hooks(&self)
Runs all shutdown hooks.
Hooks run in reverse registration order (LIFO). Errors are logged but do not stop other hooks from running.
This consumes the shutdown hooks - they can only be run once.
Sourcepub fn transfer_shutdown_hooks(&self, controller: &ShutdownController)
pub fn transfer_shutdown_hooks(&self, controller: &ShutdownController)
Transfers shutdown hooks to a ShutdownController.
This moves all registered shutdown hooks to the controller, which will run them during the appropriate shutdown phase.
Call this when integrating with the server’s shutdown mechanism.
Sourcepub fn pending_startup_hooks(&self) -> usize
pub fn pending_startup_hooks(&self) -> usize
Returns the number of pending startup hooks.
Sourcepub fn pending_shutdown_hooks(&self) -> usize
pub fn pending_shutdown_hooks(&self) -> usize
Returns the number of pending shutdown hooks.