Code Explainers

Code explainers tagged #shared-state

rust
use axum::{extract::{Path, State}, http::StatusCode, Json};
use dashmap::DashMap;
use serde::Serialize;
use std::sync::Arc;

Request coalescing in an Axum handler

caching concurrency request-coalescing
Advanced 8 steps
rust
use axum::{
    extract::{Path, State},
    http::StatusCode,
    response::IntoResponse,

Building a GitHub proxy handler in Axum

shared-state http-client error-mapping
Intermediate 9 steps
rust
use axum::{
    extract::{Request, State},
    http::{HeaderValue, StatusCode},
    middleware::Next,

API version headers with Axum middleware

middleware http-headers versioning
Intermediate 8 steps
rust
use std::sync::Arc;
use std::time::Duration;
 
use axum::{

Long-polling with Axum and Tokio Notify

long-polling concurrency shared-state
Advanced 8 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    Json,

Idempotent webhook handling in Axum

deduplication idempotency shared-state
Intermediate 8 steps
rust
use axum::{
    extract::State,
    routing::{get, post, MethodRouter},
    Json, Router,

Self-documenting routes in Axum

builder-pattern closures shared-state
Intermediate 8 steps
rust
use axum::{
    async_trait,
    extract::{FromRequestParts, State},
    http::{request::Parts, StatusCode},

Idempotent payments with an Axum extractor

idempotency extractors shared-state
Intermediate 8 steps
rust
use std::time::Duration;
 
use axum::{
    extract::State,

Rate-limiting an expensive Axum route with tower

middleware concurrency-limiting shared-state
Intermediate 9 steps
rust
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use chrono::{Duration, Utc};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, sync::Arc};

Refresh token rotation in Axum

authentication token-rotation reuse-detection
Advanced 9 steps
rust
use std::sync::Arc;
 
use axum::{
    extract::State,

Offloading work with a channel in Axum

background-jobs message-passing shared-state
Intermediate 9 steps
rust
use axum::{
    extract::{Path, State},
    http::StatusCode,
    routing::get,

Building a JSON user API in Axum

routing shared-state json-serialization
Intermediate 8 steps
rust
use axum::{
    body::Bytes,
    extract::State,
    http::StatusCode,

Handling raw byte uploads in Axum

extractors shared-state request-limits
Intermediate 7 steps
rust
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::thread;
 

Aggregating metrics across threads in Rust

concurrency shared-state mutex
Intermediate 7 steps
rust
use axum::{
    response::sse::{Event, KeepAlive, Sse},
    routing::get,
    Router,

Streaming live price ticks with SSE in Axum

server-sent-events broadcast-channel streaming
Advanced 8 steps
rust
use std::net::SocketAddr;
use std::time::Duration;
 
use axum::{routing::get, Json, Router};

Per-IP rate limiting in Axum with tower-governor

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

Building a nested REST API router in Axum

routing extractors shared-state
Intermediate 8 steps
rust
use axum::{
    extract::State,
    http::StatusCode,
    response::IntoResponse,

An async job queue handler in Axum

background-jobs async http-202
Intermediate 9 steps