Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Introduction

Volter is a production-grade, async-first web framework for Rust. It follows the same architectural principles as tower — every component is a Service or a Layer, making the framework naturally composable.

Why Volter?

Rust has several excellent web frameworks. Volter was built for teams that want:

  • No panics in request paths — deny-level lints (unwrap_used, expect_used, panic, indexing_slicing) are enforced in every library crate.
  • Tower-native composition — use any tower::Layer or tower::Service without adapters. Middleware, routing, and handlers all speak the same Service protocol.
  • Compile-time safety — wrong state type? It won’t compile. Missing extractor? It won’t compile.
  • No macros required — the core API is pure Rust. Derive macros and attribute macros are optional sugar.

Design Principles

  1. Everything is a Service. Router<S> implements tower::Service<Request>. Middleware is tower::Layer. Handlers become Services via HandlerService.

  2. Rejection is a first-class concept. Every extractor defines its own rejection type that implements IntoResponse. A missing query parameter and an invalid JSON body produce different, predictable HTTP responses.

  3. State is typed. Application state is checked at compile time. If your handler extracts State<AppConfig>, you must provide a Router<AppConfig>.

  4. Panics are caught. Wrap your router with CatchPanicLayer to turn handler panics into 500 Internal Server Error responses, keeping the server alive.

Crate Layout

Volter is organised as a set of focused crates, all re-exported through the top-level volter crate:

CratePurpose
volterMeta-crate — re-exports everything
volter-coreCore traits: Handler, FromRequest, IntoResponse, State
volter-routerRouter, MethodRouter, route construction
volter-extractExtractors: Json, Query, Path, Extension
volter-middlewareBuilt-in middleware: TraceLayer, CorsLayer, etc.
volter-wsWebSocket support
volter-macrosOptional derive and attribute macros
volter-testingTestClient for integration tests
volter-cliCLI tool for scaffolding (volter new)

Quick Start

use tokio::net::TcpListener;
use volter::{get, serve, Router};

async fn hello() -> &'static str {
    "Hello, World!"
}

#[tokio::main]
async fn main() -> Result<(), volter::BoxError> {
    let app = Router::new().route("/", get(hello));
    let listener = TcpListener::bind("0.0.0.0:3000").await?;
    serve(listener, app).await
}