Skip to main content

Module app

Module app 

Source
Expand description

Application builder and runtime for fastapi_rust.

This module provides a fluent API for building web applications with type-safe route registration, middleware ordering, and shared state.

§Design Principles

  • Fluent Builder API: Chain methods to configure the application
  • Type-Safe State: Shared state is type-checked at compile time
  • Explicit Middleware Order: Middleware runs in registration order
  • Compile-Time Validation: Invalid configurations fail at compile time

§Example

use fastapi_core::app::{App, AppBuilder};
use fastapi_core::{Request, Response, RequestContext};

async fn hello(ctx: &RequestContext, req: &mut Request) -> Response {
    Response::ok().body_text("Hello, World!")
}

async fn health(ctx: &RequestContext, req: &mut Request) -> Response {
    Response::ok().body_json(&serde_json::json!({"status": "healthy"}))
}

let app = App::builder()
    .route("/", Method::Get, hello)
    .route("/health", Method::Get, health)
    .middleware(RequestIdMiddleware::new())
    .middleware(LoggingMiddleware::new())
    .build();

Structs§

App
A configured web application.
AppBuilder
Builder for constructing an App.
AppConfig
Application configuration for the FastAPI Rust framework.
ExceptionHandlers
Registry for custom exception handlers.
LifespanError
Error during lifespan startup.
LifespanScope
Scope returned by a lifespan function containing state and cleanup logic.
MountedApp
A mounted sub-application with its path prefix.
RouteEntry
A registered route with its handler.
StartupHookError
Error returned when a startup hook fails.
StateContainer
Type-safe application state container.

Enums§

ConfigError
Configuration loading errors.
StartupHook
A startup hook that runs before the server starts accepting connections.
StartupOutcome
Outcome of running all startup hooks.

Traits§

HasState
Marker trait indicating that type T is present in state registry S.
RequiresState
Trait for types that require specific state to be registered.
StateRegistry
Marker trait for the type-level state registry.

Type Aliases§

BoxExceptionHandler
A boxed exception handler function.
BoxHandler
A boxed handler function.
BoxLifespanFn
Boxed lifespan function type.
BoxPanicHandler
A boxed panic handler function.