pub struct FacilitatorClient { /* private fields */ }server only.Expand description
A client for communicating with a remote x402 facilitator.
Implementations§
Source§impl FacilitatorClient
impl FacilitatorClient
Sourcepub const DEFAULT_SUPPORTED_CACHE_TTL: Duration
pub const DEFAULT_SUPPORTED_CACHE_TTL: Duration
Default /supported cache TTL used by Self::try_new.
Sourcepub const DEFAULT_TIMEOUT: Duration
pub const DEFAULT_TIMEOUT: Duration
Default per-request timeout. Aligned with the Go/TS clients (30 s).
Sourcepub const fn verify_url(&self) -> &Url
pub const fn verify_url(&self) -> &Url
Returns the computed ./verify URL relative to Self::base_url.
Sourcepub const fn settle_url(&self) -> &Url
pub const fn settle_url(&self) -> &Url
Returns the computed ./settle URL relative to Self::base_url.
Sourcepub const fn supported_url(&self) -> &Url
pub const fn supported_url(&self) -> &Url
Returns the computed ./supported URL relative to Self::base_url.
Sourcepub const fn supported_cache(&self) -> Option<&SupportedCache>
pub const fn supported_cache(&self) -> Option<&SupportedCache>
Returns the supported cache when one is configured.
Sourcepub fn try_new(
base_url: Url,
) -> Result<FacilitatorClient, FacilitatorClientError>
pub fn try_new( base_url: Url, ) -> Result<FacilitatorClient, FacilitatorClientError>
Constructs a new FacilitatorClient from a base URL.
Sets up ./verify, ./settle, and ./supported relative to the base.
/supported is cached for Self::DEFAULT_SUPPORTED_CACHE_TTL.
Call Self::without_supported_cache to disable.
§Errors
Returns FacilitatorClientError if URL construction fails.
Sourcepub fn with_auth<F, Fut>(self, create: F) -> FacilitatorClient
pub fn with_auth<F, Fut>(self, create: F) -> FacilitatorClient
Sets the callback that produces path-keyed facilitator auth headers.
The JSON object must be keyed by verify, settle, supported, and
optionally bazaar. A flat headers object is rejected when headers
are resolved.
Sourcepub const fn with_timeout(self, timeout: Duration) -> FacilitatorClient
pub const fn with_timeout(self, timeout: Duration) -> FacilitatorClient
Sets a timeout for all future requests.
Sourcepub fn with_supported_cache_ttl(self, ttl: Duration) -> FacilitatorClient
pub fn with_supported_cache_ttl(self, ttl: Duration) -> FacilitatorClient
Enables TTL caching of the /supported response.
Sourcepub fn without_supported_cache(self) -> FacilitatorClient
pub fn without_supported_cache(self) -> FacilitatorClient
Disables caching for the /supported endpoint.
Sourcepub async fn create_auth_headers(
&self,
path: &str,
) -> Result<HeaderMap, FacilitatorClientError>
pub async fn create_auth_headers( &self, path: &str, ) -> Result<HeaderMap, FacilitatorClientError>
Resolves authentication headers for one facilitator path.
§Errors
Returns FacilitatorClientError::FlatAuthHeaders when the callback
result has no object-valued verify/settle/supported/bazaar key
and some value is not a header object. Returns
FacilitatorClientError::InvalidAuthHeader when a path object has a
non-string or illegal header. Propagates callback Err values.
Sourcepub async fn verify(
&self,
request: &VerifyRequest,
) -> Result<VerifyResponse, FacilitatorError>
pub async fn verify( &self, request: &VerifyRequest, ) -> Result<VerifyResponse, FacilitatorError>
Sends a POST /verify request to the facilitator.
2xx or non-2xx Invalid JSON is Ok. Non-2xx Valid JSON, timeout,
connect/DNS/TLS/body failures, and malformed 2xx bodies are
FacilitatorError::Transport (502).
§Errors
Returns FacilitatorError for transport, auth, or parse failures.
Sourcepub async fn settle(
&self,
request: &SettleRequest,
) -> Result<SettleResponse, FacilitatorError>
pub async fn settle( &self, request: &SettleRequest, ) -> Result<SettleResponse, FacilitatorError>
Sends a POST /settle request to the facilitator.
2xx Success may have transaction: "". Non-2xx Failure is Ok.
Non-2xx Success is Transport.
§Errors
Returns FacilitatorError for transport, auth, or parse failures.
Sourcepub async fn supported(&self) -> Result<SupportedResponse, FacilitatorError>
pub async fn supported(&self) -> Result<SupportedResponse, FacilitatorError>
Sends a GET /supported request to the facilitator.
Results are cached when a TTL is configured (the default).
§Errors
Returns FacilitatorError if the HTTP request fails.
Sourcepub async fn supported_inner(
&self,
) -> Result<SupportedResponse, FacilitatorError>
pub async fn supported_inner( &self, ) -> Result<SupportedResponse, FacilitatorError>
GET /supported with 429-only retries, bypassing the TTL cache.
§Errors
Returns FacilitatorError if the HTTP request fails or the body is
not a well-formed SupportedResponse.
Trait Implementations§
Source§impl Clone for FacilitatorClient
impl Clone for FacilitatorClient
Source§fn clone(&self) -> FacilitatorClient
fn clone(&self) -> FacilitatorClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FacilitatorClient
impl Debug for FacilitatorClient
Source§impl Facilitator for FacilitatorClient
impl Facilitator for FacilitatorClient
Source§async fn verify(
&self,
request: VerifyRequest,
) -> Result<VerifyResponse, FacilitatorError>
async fn verify( &self, request: VerifyRequest, ) -> Result<VerifyResponse, FacilitatorError>
Source§async fn settle(
&self,
request: SettleRequest,
) -> Result<SettleResponse, FacilitatorError>
async fn settle( &self, request: SettleRequest, ) -> Result<SettleResponse, FacilitatorError>
Source§async fn supported(&self) -> Result<SupportedResponse, FacilitatorError>
async fn supported(&self) -> Result<SupportedResponse, FacilitatorError>
Source§impl TryFrom<&str> for FacilitatorClient
impl TryFrom<&str> for FacilitatorClient
Source§type Error = FacilitatorClientError
type Error = FacilitatorClientError
Source§fn try_from(
value: &str,
) -> Result<FacilitatorClient, <FacilitatorClient as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<FacilitatorClient, <FacilitatorClient as TryFrom<&str>>::Error>
Source§impl TryFrom<String> for FacilitatorClient
impl TryFrom<String> for FacilitatorClient
Source§type Error = FacilitatorClientError
type Error = FacilitatorClientError
Source§fn try_from(
value: String,
) -> Result<FacilitatorClient, <FacilitatorClient as TryFrom<String>>::Error>
fn try_from( value: String, ) -> Result<FacilitatorClient, <FacilitatorClient as TryFrom<String>>::Error>
Auto Trait Implementations§
impl !RefUnwindSafe for FacilitatorClient
impl !UnwindSafe for FacilitatorClient
impl Freeze for FacilitatorClient
impl Send for FacilitatorClient
impl Sync for FacilitatorClient
impl Unpin for FacilitatorClient
impl UnsafeUnpin for FacilitatorClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynFacilitator for Twhere
T: Facilitator + ?Sized,
impl<T> DynFacilitator for Twhere
T: Facilitator + ?Sized,
Source§fn verify(
&self,
request: VerifyRequest,
) -> Pin<Box<dyn Future<Output = Result<VerifyResponse, FacilitatorError>> + Send + '_>>
fn verify( &self, request: VerifyRequest, ) -> Pin<Box<dyn Future<Output = Result<VerifyResponse, FacilitatorError>> + Send + '_>>
Facilitator::verify.Source§fn settle(
&self,
request: SettleRequest,
) -> Pin<Box<dyn Future<Output = Result<SettleResponse, FacilitatorError>> + Send + '_>>
fn settle( &self, request: SettleRequest, ) -> Pin<Box<dyn Future<Output = Result<SettleResponse, FacilitatorError>> + Send + '_>>
Facilitator::settle.Source§fn supported(
&self,
) -> Pin<Box<dyn Future<Output = Result<SupportedResponse, FacilitatorError>> + Send + '_>>
fn supported( &self, ) -> Pin<Box<dyn Future<Output = Result<SupportedResponse, FacilitatorError>> + Send + '_>>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more