pub struct X402HttpClient { /* private fields */ }Expand description
reqwest-middleware that automatically handles HTTP 402 responses.
When a response with status 402 is received, the middleware:
- Decodes the
PAYMENT-REQUIREDheader (or V1 body) - Delegates to
X402Client::create_payment_payloadto build a signed payload - Retries the request with the
PAYMENT-SIGNATUREheader attached
§Example
use std::sync::Arc;
use r402::client::X402Client;
use r402_http::client::X402HttpClient;
use reqwest_middleware::ClientBuilder;
let x402_client = Arc::new(X402Client::new());
// Register scheme clients on x402_client...
let http_client = ClientBuilder::new(reqwest::Client::new())
.with(X402HttpClient::new(x402_client))
.build();Corresponds to Python SDK’s x402HTTPClient + PaymentRoundTripper.
Implementations§
Source§impl X402HttpClient
impl X402HttpClient
Sourcepub fn new(client: Arc<X402Client>) -> Self
pub fn new(client: Arc<X402Client>) -> Self
Creates a new middleware wrapping the given x402 client.
Sourcepub fn from_client(client: X402Client) -> Self
pub fn from_client(client: X402Client) -> Self
Creates a new middleware from an owned X402Client.
Convenience wrapper that wraps the client in an Arc internally.
Sourcepub fn build_reqwest(client: X402Client) -> ClientWithMiddleware
pub fn build_reqwest(client: X402Client) -> ClientWithMiddleware
Builds a reqwest_middleware::ClientWithMiddleware with x402 payment
handling from an owned X402Client.
This is the simplest way to get a payment-capable HTTP client:
ⓘ
use r402::client::X402Client;
use r402_http::client::X402HttpClient;
let http_client = X402HttpClient::build_reqwest(
X402Client::builder()
.register("eip155:*".into(), Box::new(evm_scheme))
.build()
);Trait Implementations§
Source§impl Clone for X402HttpClient
impl Clone for X402HttpClient
Source§fn clone(&self) -> X402HttpClient
fn clone(&self) -> X402HttpClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for X402HttpClient
impl Debug for X402HttpClient
Source§impl Middleware for X402HttpClient
impl Middleware for X402HttpClient
Source§fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: Request,
extensions: &'life1 mut Extensions,
next: Next<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
req: Request,
extensions: &'life1 mut Extensions,
next: Next<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Invoked with a request before sending it. If you want to continue processing the request,
you should explicitly call
next.run(req, extensions). Read moreAuto Trait Implementations§
impl Freeze for X402HttpClient
impl !RefUnwindSafe for X402HttpClient
impl Send for X402HttpClient
impl Sync for X402HttpClient
impl Unpin for X402HttpClient
impl !UnwindSafe for X402HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more