Expand description
§OpenLibx402 Actix Web
Actix Web framework integration for the X402 payment protocol.
This library provides middleware and extractors to protect Actix Web endpoints with payment requirements using the X402 protocol.
§Example
use actix_web::{web, App, HttpResponse, HttpServer};
use openlibx402_actix::{PaymentExtractor, X402Config, X402State};
async fn premium_data(auth: PaymentExtractor) -> HttpResponse {
HttpResponse::Ok().json(serde_json::json!({
"message": "Premium content!",
"payment_id": auth.authorization.payment_id
}))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let config = X402Config {
payment_address: "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU".to_string(),
token_mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v".to_string(),
network: "solana-devnet".to_string(),
rpc_url: None,
auto_verify: true,
};
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(X402State { config: config.clone() }))
.route("/premium", web::get().to(premium_data))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}Structs§
- Payment
Extractor - Extractor that enforces payment requirements
- Payment
Requirement - Payment requirement configuration for a specific endpoint
- X402
Config - Global X402 configuration
- X402
State - Application state containing X402 configuration
Enums§
- Payment
Error - Error type for payment operations
Functions§
- create_
payment_ request - Create a payment request for an endpoint
- payment_
required_ response - Helper function to create a 402 Payment Required response