Skip to main content

Module server

Module server 

Source
Available on crate feature server only.
Expand description

Axum middleware for enforcing x402 payments on protected routes (V2-only).

This middleware validates incoming payment headers using a configured x402 facilitator, verifies the payment, executes the request, and settles valid payments after successful execution. If the handler returns an error (4xx/5xx), settlement is skipped.

Returns a 402 Payment Required response if the request lacks a valid payment.

See X402Middleware for full configuration options. For low-level interaction with the facilitator, see facilitator::FacilitatorClient.

§Settlement Modes

Re-exports§

pub use cors::X402_EXPOSED_HEADERS;
pub use cors::ensure_expose_headers;
pub use hooks::DynPaygateHooks;
pub use hooks::NoopPaygateHooks;
pub use hooks::PaygateHooks;
pub use hooks::ProtectedRequestOutcome;
pub use layer::SettlementMode;
pub use layer::X402LayerBuilder;
pub use layer::X402Middleware;
pub use paygate::BackgroundSettlementTracker;
pub use paygate::Paygate;
pub use paygate::PaygateBuilder;
pub use paygate::PaygateError;
pub use paygate::ResourceTemplate;
pub use paygate::VerificationError;
pub use paygate::VerifiedPayment;
pub use paygate::settlement_to_header;
pub use pricing::DynamicPriceTags;
pub use pricing::PriceTagSource;
pub use pricing::StaticPriceTags;
pub use status::reason_to_status;
pub use upto::UptoActualAmount;

Modules§

cors
CORS helpers for exposing x402 response headers to browser clients.
facilitator
A r402_core::facilitator::Facilitator implementation that interacts with a remote x402 Facilitator over HTTP.
hooks
Paygate-level lifecycle hooks.
layer
Axum middleware for enforcing x402 payments on protected routes.
paygate
Core payment gate logic for enforcing x402 payments (V2-only).
pricing
Price tag sources for the x402 payment gate.
status
Maps x402 error reasons to HTTP status codes.
upto
HTTP-level support for the x402 “upto” scheme.