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.
ExceptionHandlers
Registry for custom exception handlers.
OpenApiConfig
Configuration for OpenAPI documentation generation.
RouteEntry
A registered route with its handler.
StartupHookError
Error returned when a startup hook fails.
StateContainer
Type-safe application state container.
WebSocketRouteEntry
A registered websocket route with its handler.

Enums§

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

Type Aliases§

BoxExceptionHandler
A boxed exception handler function.
BoxHandler
A boxed handler function.
BoxWebSocketHandler
A boxed websocket handler function.