MPP.Client.Req (mpp v0.16.0)

Copy Markdown View Source

Payment-aware Req plugin.

Intercepts HTTP 402 responses, selects a challenge through MPP.Client.SelectionPolicy, pays via MPP.Client.MultiProvider, and retries with Authorization: Payment. Non-402 responses pass through unchanged.

Req.new()
|> MPP.Client.Req.attach(provider: my_provider)
|> Req.get(url: "https://api.example.com/resource")

This is the Elixir counterpart of mpp-rs PaymentExt and mppx Fetch.from().

A 402 that arrives after a redirect changed the request origin is refused (:cross_origin_redirect) so a payment credential is never attached to a different host, scheme, or port than the caller asked for (mpp-rs #379).

API Functions

FunctionArityDescriptionParam Kinds
attach2Attach payment-aware 402 handling to a Req pipeline.request: value, opts: value

Summary

Functions

Attach payment-aware 402 handling to a Req pipeline.

Functions

attach(request, opts)

@spec attach(
  Req.Request.t(),
  keyword()
) :: Req.Request.t()

Attach payment-aware 402 handling to a Req pipeline.

Options

  • :provider — required. An MPP.Client.MultiProvider, a {module, config} tuple, or a provider module
  • :selectionMPP.Client.SelectionPolicy.t(). Defaults to :server_order, or {:accept_payment, entries} when :accept_payment is set
  • :accept_payment — preference entries advertised on outgoing requests and used as the default ranking policy. q values are preserved on the wire
  • :accept_policyMPP.Client.AcceptPolicy.t() gating header injection (default :always)
  • :max_payment_retries — payment attempts after a 402 (default 3)