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

Crate Reference

Throughout this book, we pull in quite a few crates. If you ever find yourself thinking “wait, which crate was that again?”, this is the page to come back to. I’ve organized everything by concern so you can quickly find what you need and understand why it’s in our stack.

Core Framework

CratePurposeNotes
axumHTTP routing, extractors, and handler frameworkThe foundation. Use with the macros feature for #[debug_handler].
tokioAsync runtimeUse features = ["full"] unless you need to minimize dependencies.
towerMiddleware abstractions and utilitiesProvides ServiceBuilder, ServiceExt (for oneshot in tests), and composable layers.
tower-httpHTTP-specific middlewareCORS, compression, tracing, timeouts, request IDs, body limits, and more. Enable features selectively.
hyperHTTP implementationYou’ll rarely interact with hyper directly when using Axum, but it’s the HTTP engine under the hood.

Serialization and Data

CratePurposeNotes
serdeSerialization frameworkUse features = ["derive"] for #[derive(Serialize, Deserialize)].
serde_jsonJSON serializationAxum’s Json extractor uses this under the hood.
uuidUUID generation and parsingUse features = ["v4", "serde"] for random UUIDs with serde support.
chronoDate and time handlingUse features = ["serde"] for serialization. Prefer DateTime<Utc> for timestamps.

Database

CratePurposeNotes
sqlxAsync SQL with compile-time checkingOur go-to for most Axum projects. Supports PostgreSQL, MySQL, and SQLite.
dieselType-safe ORM and query builderMature and well-tested. Use diesel-async for async support.
sea-ormActiveRecord-style async ORMWorth considering if raw SQL feels like too much ceremony for your use case.
axum-sqlx-txRequest-scoped SQLx transactionsBegins a transaction for each request automatically, then commits or rolls back based on the response status.

Error Handling

CratePurposeNotes
thiserrorDerive macros for custom error typesWe use this for domain errors and our AppError enum where we need to match on variants.
anyhowFlexible error type with context chainingGreat for the catch-all Internal variant and in infrastructure code. Don’t be shy with .context().

Validation

CratePurposeNotes
validatorDerive-based input validationSupports email, url, length, range, and custom validators.
gardeAlternative validation with const genericsA newer take on validator with a different API style.
axum-validPre-built validated extractors for AxumIntegrates with validator, garde, and validify. Saves you from writing your own extractors.

Authentication and Security

CratePurposeNotes
jsonwebtokenJWT encoding and decodingThe go-to for JWT-based auth in Rust.
argon2Password hashingWhat I’d recommend for password hashing today. Prefer it over bcrypt for new projects.
axum-loginSession-based authenticationA good fit for traditional web apps with server-side sessions.
axum-csrf-sync-patternCSRF protectionImplements the OWASP Synchronizer Token Pattern.
tower-governorRate limitingPer-IP rate limiting using the governor algorithm.
tower-sessionsSession middlewareServer-side session management with pluggable backends.

Configuration

CratePurposeNotes
configLayered configuration loadingSupports files, environment variables, and multiple formats.
dotenvyLoad .env filesFork of the original dotenv crate. Call .ok() instead of .unwrap() so it doesn’t blow up in production.
secrecySensitive value protectionWrap secrets in SecretString. It’ll redact them in debug output and zero memory on drop.

Observability

CratePurposeNotes
tracingStructured logging and spansIf you’re doing structured logging in Rust, this is what everyone reaches for.
tracing-subscriberTracing output configurationUse features = ["env-filter", "json"] for environment-based filtering and JSON output.
tracing-opentelemetryBridge tracing to OpenTelemetryConverts tracing spans into OpenTelemetry spans for distributed tracing.
opentelemetryOpenTelemetry APICore API for distributed tracing and metrics.
opentelemetry-otlpOTLP exporterExports traces to Jaeger, Tempo, Datadog, and other OTLP-compatible backends.
axum-tracing-opentelemetryAxum OpenTelemetry integrationAutomatic trace context propagation for Axum.

API Documentation

CratePurposeNotes
utoipaCompile-time OpenAPI spec generationGenerates OpenAPI 3.0 specs from code annotations.
utoipa-swagger-uiSwagger UI for utoipaServes an interactive API documentation UI at a configurable path.

Testing

CratePurposeNotes
tower (ServiceExt)Integration testing without a serverUse oneshot() to send requests through the router directly.
mockallAutomatic mock generationGenerates mock implementations of your traits for unit testing.
axum-testTesting library for AxumGives you a TestClient with a nicer API than raw oneshot.

HTTP Client

CratePurposeNotes
reqwestAsync HTTP clientThe HTTP client you’ll see in most Rust projects. Async-native with connection pooling.

gRPC

CratePurposeNotes
tonicgRPC frameworkNative async gRPC client and server. Integrates with Tower middleware.
tonic-prostTonic + Prost runtimeRuntime support for tonic services using prost-generated types.
prostProtocol BuffersProtobuf serialization/deserialization. Used by tonic for message types.
tonic-prost-buildProto code generationCompiles .proto files into Rust code at build time. Goes in [build-dependencies]. This replaced direct tonic-build usage as of tonic 0.14.
tonic-reflectiongRPC server reflectionLets grpcurl and other tools discover your service’s API.

Async Utilities

CratePurposeNotes
tokio-utilExtended Tokio utilitiesProvides CancellationToken for structured shutdown, plus codecs and other helpers.
futuresFuture combinatorsProvides FuturesUnordered, StreamExt, and other utilities for working with async streams.

Background Jobs

CratePurposeNotes
apalisBackground task processingType-safe, extensible, supports PostgreSQL/Redis/SQLite backends. Built-in monitoring and graceful shutdown.
fangPersistent job queueWorkers in separate Tokio tasks with auto-restart on panic. Cron scheduling and retry backoff.
backieAsync task queuePostgreSQL-backed, designed for horizontal scaling across multiple processes.