Skip to main content

x402_gateway/
lib.rs

1//! # tempo-x402-gateway
2//!
3//! API gateway that adds **x402 payment rails** to any HTTP endpoint.
4//!
5//! Register upstream APIs with a price, and clients pay per-request through the
6//! gateway at `/g/{slug}/{path}`. Payments are verified and settled on-chain before
7//! the request is proxied.
8//!
9//! ## Features
10//!
11//! - **Endpoint registration** with atomic slug reservation (`BEGIN IMMEDIATE`)
12//! - **Embedded facilitator** — runs in-process when `FACILITATOR_PRIVATE_KEY` is set
13//! - **Proxy with SSRF protection** — HTTPS-only targets, private IP blocking, DNS validation
14//! - **Per-endpoint analytics** — request counts, payment counts, revenue tracking
15//! - **Prometheus metrics** — `ENDPOINT_PAYMENTS` and `ENDPOINT_REVENUE` with slug labels
16//! - **Pre-flight reachability check** before payment settlement (don't charge for dead targets)
17//! - **Extensible database** — downstream crates (x402-node) add tables via `execute_schema()`
18//!
19//! ## Modules
20//!
21//! - [`config`] — Gateway configuration ([`config::GatewayConfig`])
22//! - [`db`] — SQLite database with extensible schema
23//! - [`middleware`] — Payment processing, header encoding, 402 response construction
24//! - [`proxy`] — HTTP proxy with header stripping and SSRF protection
25//! - [`routes`] — Endpoint registration, gateway proxy, analytics, health
26//! - [`state`] — Shared application state
27//! - [`validation`] — URL and SSRF validation
28//! - [`metrics`] — Prometheus metrics
29//! - [`facilitator`] — Embedded facilitator bootstrap
30//!
31//! Part of the [`tempo-x402`](https://docs.rs/tempo-x402) workspace.
32
33pub mod config;
34pub mod cors;
35pub mod db;
36pub mod error;
37pub mod facilitator;
38pub mod metrics;
39pub mod middleware;
40pub mod proxy;
41pub mod routes;
42pub mod state;
43pub mod validation;
44
45pub use config::GatewayConfig;
46pub use db::Database;
47pub use error::GatewayError;
48pub use state::AppState;