Expand description
Per-route Axum payment gate middleware.
Provides PaymentGate for creating per-route payment layers that
integrate natively with Axum’s .layer() method. Unlike
super::server::PaymentGateLayer which uses a global route map with
string-based matching, this module lets Axum handle routing while each
route independently configures its payment requirements.
§Example
ⓘ
use std::sync::Arc;
use r402::server::X402ResourceServer;
use r402_http::paygate::PaymentGate;
use r402_http::types::{PaymentOption, RouteConfig};
use axum::{Router, routing::get};
let server = Arc::new(X402ResourceServer::new());
let gate = PaymentGate::new(server);
let app = Router::new()
.route("/weather", get(weather_handler).layer(
gate.route(RouteConfig::single(PaymentOption {
scheme: "exact".into(),
pay_to: "0xRecipient".into(),
price: serde_json::json!("0.01"),
network: "eip155:8453".into(),
max_timeout_seconds: None,
extra: None,
}))
.with_description("Weather forecast data")
))
.route("/premium", get(premium_handler).layer(
gate.route(RouteConfig::single(PaymentOption {
scheme: "exact".into(),
pay_to: "0xRecipient".into(),
price: serde_json::json!("1.00"),
network: "eip155:8453".into(),
max_timeout_seconds: None,
extra: None,
}))
.with_description("Premium content")
.with_mime_type("application/json")
));Structs§
- Payment
Gate - Per-route payment gate factory.
- Payment
Route Layer - Per-route Tower
Layerthat enforces x402 payment requirements. - Payment
Route Service - Per-route Tower
Servicethat enforces x402 payment requirements.