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.
- Exception
Handlers - Registry for custom exception handlers.
- Lifespan
Error - Error during lifespan startup.
- Lifespan
Scope - Scope returned by a lifespan function containing state and cleanup logic.
- Mounted
App - A mounted sub-application with its path prefix.
- Route
Entry - A registered route with its handler.
- Startup
Hook Error - Error returned when a startup hook fails.
- State
Container - Type-safe application state container.
Enums§
- Config
Error - Configuration loading errors.
- Startup
Hook - A startup hook that runs before the server starts accepting connections.
- Startup
Outcome - Outcome of running all startup hooks.
Traits§
- HasState
- Marker trait indicating that type T is present in state registry S.
- Requires
State - Trait for types that require specific state to be registered.
- State
Registry - Marker trait for the type-level state registry.
Type Aliases§
- BoxException
Handler - A boxed exception handler function.
- BoxHandler
- A boxed handler function.
- BoxLifespan
Fn - Boxed lifespan function type.
- BoxPanic
Handler - A boxed panic handler function.