Code Explainers

Axum code explainers

rust
use axum::{
    extract::{Path, State},
    response::sse::{Event, KeepAlive, Sse},
};

Streaming import progress with SSE in Axum

server-sent-events streams watch-channel
Advanced 7 steps
rust
use axum::{
    async_trait,
    extract::{rejection::JsonRejection, FromRequest, Request},
    http::StatusCode,

A validated JSON extractor in Axum

extractors validation error-handling
Intermediate 8 steps
rust
use axum::{
    extract::FromRequestParts,
    http::{request::Parts, HeaderMap, StatusCode},
};

Building a replay-guard extractor in Axum

custom-extractor replay-protection shared-state
Advanced 8 steps
rust
use axum::{
    body::Body,
    extract::Request,
    http::{header::SET_COOKIE, HeaderValue},

Flash messages via Axum middleware

middleware shared-state cookies
Intermediate 8 steps
rust
use axum::{
    extract::{FromRef, FromRequestParts, State},
    http::{header::ACCEPT_LANGUAGE, request::Parts, StatusCode},
    response::{IntoResponse, Response},

A custom Accept-Language extractor in Axum

extractors internationalization http-headers
Advanced 8 steps
rust
use axum::{
    body::Body,
    extract::Request,
    http::{header, StatusCode},

A CSRF verification middleware in Axum

csrf middleware security
Intermediate 10 steps
rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{header::HeaderValue, request::Parts, HeaderName},

Propagating trace context in Axum extractors

extractors distributed-tracing http-headers
Intermediate 8 steps
rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{request::Parts, StatusCode},

A proof-of-work extractor in Axum

proof-of-work extractors hashing
Advanced 9 steps
rust
use std::collections::HashMap;
use std::sync::Arc;
 
use axum::body::Bytes;

A concurrent webhook dispatcher in Axum

trait-objects concurrency shared-state
Intermediate 9 steps
rust
use axum::{
    extract::{Path, State},
    http::HeaderMap,
    response::{Html, IntoResponse},

Building an HTMX-aware toggle handler in Axum

extractors htmx sqlx
Intermediate 8 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{Request, StatusCode},

A sliding-window rate limiter in Axum

rate-limiting middleware sliding-window
Intermediate 10 steps
rust
use axum::{
    extract::{Path, State},
    routing::{get, post},
    Json, Router,

Composing Axum apps from feature modules

trait objects modular routing shared state
Intermediate 8 steps
rust
use axum::{
    extract::{Path, State},
    http::StatusCode,
    Json,

Distinguishing absent from null in an Axum PATCH

partial-update serde nullable-fields
Advanced 8 steps
rust
use std::sync::Arc;
 
use axum::{
    extract::{FromRef, State},

Substate extraction with FromRef in Axum

state-management routing middleware
Intermediate 8 steps
rust
use std::sync::Arc;
use std::collections::HashMap;
use axum::{
    extract::State,

Hot-reloadable config with shared state in Axum

shared-state concurrency rwlock
Intermediate 7 steps
rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{header::HeaderName, request::Parts, StatusCode},

A custom tenant extractor in Axum

extractors middleware error-handling
Intermediate 7 steps
rust
#[derive(Debug, Deserialize)]
pub struct SearchParams {
    #[serde(default)]
    q: String,

Building a safe search query in Axum

query parameters deserialization sql-building
Intermediate 10 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{header, StatusCode},

Streaming a DB migration with Axum

streaming keyset-pagination backpressure
Advanced 8 steps