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.
- Exception
Handlers - Registry for custom exception handlers.
- Open
ApiConfig - Configuration for OpenAPI documentation generation.
- 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.
- WebSocket
Route Entry - A registered websocket route with its handler.
Enums§
- Startup
Hook - A startup hook that runs before the server starts accepting connections.
- Startup
Outcome - Outcome of running all startup hooks.
Type Aliases§
- BoxException
Handler - A boxed exception handler function.
- BoxHandler
- A boxed handler function.
- BoxWeb
Socket Handler - A boxed websocket handler function.