Documentation
¶
Overview ¶
THIS FILE IS AUTO-GENERATED - DO NOT EDIT
Package http provides HTTP-specific implementations of x402 components. This includes HTTP-aware clients, services, and facilitator clients.
THIS FILE IS AUTO-GENERATED - DO NOT EDIT
Index ¶
- Constants
- func Do(ctx context.Context, req *http.Request, x402Client *x402HTTPClient) (*http.Response, error)
- func Get(ctx context.Context, url string, x402Client *x402HTTPClient) (*http.Response, error)
- func NewClient(client *x402.X402Client) *x402HTTPClient
- func NewServer(routes RoutesConfig, opts ...x402.ResourceServerOption) *x402HTTPResourceServer
- func Newx402HTTPClient(client *x402.X402Client) *x402HTTPClient
- func Newx402HTTPResourceServer(routes RoutesConfig, opts ...x402.ResourceServerOption) *x402HTTPResourceServer
- func Post(ctx context.Context, url string, body io.Reader, x402Client *x402HTTPClient) (*http.Response, error)
- func WrapClient(client *http.Client, x402Client *x402HTTPClient) *http.Client
- func WrapHTTPClientWithPayment(client *http.Client, x402Client *x402HTTPClient) *http.Client
- func Wrappedx402HTTPResourceServer(routes RoutesConfig, resourceServer *x402.X402ResourceServer) *x402HTTPResourceServer
- type AuthHeaders
- type AuthProvider
- type CompiledRoute
- type DynamicPayToFunc
- type DynamicPriceFunc
- type FacilitatorConfig
- type HTTPAdapter
- type HTTPClient
- type HTTPFacilitatorClient
- func (c *HTTPFacilitatorClient) GetSupported(ctx context.Context) (x402.SupportedResponse, error)
- func (c *HTTPFacilitatorClient) Settle(ctx context.Context, payloadBytes []byte, requirementsBytes []byte) (*x402.SettleResponse, error)
- func (c *HTTPFacilitatorClient) Verify(ctx context.Context, payloadBytes []byte, requirementsBytes []byte) (*x402.VerifyResponse, error)
- type HTTPProcessResult
- type HTTPRequestContext
- type HTTPResponseInstructions
- type HTTPServer
- type PaymentOption
- type PaymentOptions
- type PaymentRoundTripper
- type PaywallConfig
- type ProcessSettleResult
- type RouteConfig
- type RoutesConfig
- type UnpaidResponse
- type UnpaidResponseBodyFunc
Constants ¶
const ( ResultNoPaymentRequired = "no-payment-required" ResultPaymentVerified = "payment-verified" ResultPaymentError = "payment-error" )
Result type constants
const DefaultFacilitatorURL = "https://x402.org/facilitator"
DefaultFacilitatorURL is the default public facilitator
const EVMPaywallTemplate = "" /* 1928510-byte string literal not displayed */
EVMPaywallTemplate is the pre-built EVM paywall template with inlined CSS and JS
const SVMPaywallTemplate = "" /* 827883-byte string literal not displayed */
SVMPaywallTemplate is the pre-built SVM paywall template with inlined CSS and JS
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(client *x402.X402Client) *x402HTTPClient
NewClient creates a new HTTP-aware x402 client
func NewServer ¶
func NewServer(routes RoutesConfig, opts ...x402.ResourceServerOption) *x402HTTPResourceServer
NewServer creates a new HTTP resource server
func Newx402HTTPClient ¶
func Newx402HTTPClient(client *x402.X402Client) *x402HTTPClient
Newx402HTTPClient creates a new HTTP-aware x402 client
func Newx402HTTPResourceServer ¶
func Newx402HTTPResourceServer(routes RoutesConfig, opts ...x402.ResourceServerOption) *x402HTTPResourceServer
Newx402HTTPResourceServer creates a new HTTP resource server
func Post ¶
func Post(ctx context.Context, url string, body io.Reader, x402Client *x402HTTPClient) (*http.Response, error)
Post performs a POST request with automatic payment handling
func WrapClient ¶
WrapClient wraps a standard HTTP client with x402 payment handling
func WrapHTTPClientWithPayment ¶
WrapHTTPClientWithPayment wraps a standard HTTP client with x402 payment handling This allows transparent payment handling for HTTP requests
func Wrappedx402HTTPResourceServer ¶
func Wrappedx402HTTPResourceServer(routes RoutesConfig, resourceServer *x402.X402ResourceServer) *x402HTTPResourceServer
Wrappedx402HTTPResourceServer wraps an existing resource server with HTTP functionality.
Types ¶
type AuthHeaders ¶
type AuthHeaders struct {
Verify map[string]string
Settle map[string]string
Supported map[string]string
}
AuthHeaders contains authentication headers for facilitator endpoints
type AuthProvider ¶
type AuthProvider interface {
// GetAuthHeaders returns authentication headers for each endpoint
GetAuthHeaders(ctx context.Context) (AuthHeaders, error)
}
AuthProvider generates authentication headers for facilitator requests
type CompiledRoute ¶
type CompiledRoute struct {
Verb string
Regex *regexp.Regexp
Config RouteConfig
}
CompiledRoute is a parsed route ready for matching
type DynamicPayToFunc ¶
type DynamicPayToFunc func(context.Context, HTTPRequestContext) (string, error)
DynamicPayToFunc is a function that resolves payTo address dynamically based on request context
type DynamicPriceFunc ¶
DynamicPriceFunc is a function that resolves price dynamically based on request context
type FacilitatorConfig ¶
type FacilitatorConfig struct {
// URL is the base URL of the facilitator service
URL string
// HTTPClient is the HTTP client to use (optional)
HTTPClient *http.Client
// AuthProvider provides authentication headers (optional)
AuthProvider AuthProvider
// Timeout for requests (optional, defaults to 30s)
Timeout time.Duration
// Identifier for this facilitator (optional)
Identifier string
}
FacilitatorConfig configures the HTTP facilitator client
type HTTPAdapter ¶
type HTTPAdapter interface {
GetHeader(name string) string
GetMethod() string
GetPath() string
GetURL() string
GetAcceptHeader() string
GetUserAgent() string
}
HTTPAdapter provides framework-agnostic HTTP operations Implement this for each web framework (Gin, Echo, net/http, etc.)
type HTTPFacilitatorClient ¶
type HTTPFacilitatorClient struct {
// contains filtered or unexported fields
}
HTTPFacilitatorClient communicates with remote facilitator services over HTTP Implements FacilitatorClient interface (supports both V1 and V2)
func NewFacilitatorClient ¶
func NewFacilitatorClient(config *FacilitatorConfig) *HTTPFacilitatorClient
NewFacilitatorClient creates a new HTTP facilitator client
func NewHTTPFacilitatorClient ¶
func NewHTTPFacilitatorClient(config *FacilitatorConfig) *HTTPFacilitatorClient
NewHTTPFacilitatorClient creates a new HTTP facilitator client
func (*HTTPFacilitatorClient) GetSupported ¶
func (c *HTTPFacilitatorClient) GetSupported(ctx context.Context) (x402.SupportedResponse, error)
GetSupported gets supported payment kinds (shared by both V1 and V2)
func (*HTTPFacilitatorClient) Settle ¶
func (c *HTTPFacilitatorClient) Settle(ctx context.Context, payloadBytes []byte, requirementsBytes []byte) (*x402.SettleResponse, error)
Settle executes a payment (supports both V1 and V2)
func (*HTTPFacilitatorClient) Verify ¶
func (c *HTTPFacilitatorClient) Verify(ctx context.Context, payloadBytes []byte, requirementsBytes []byte) (*x402.VerifyResponse, error)
Verify checks if a payment is valid (supports both V1 and V2)
type HTTPProcessResult ¶
type HTTPProcessResult struct {
Type string
Response *HTTPResponseInstructions
PaymentPayload *types.PaymentPayload // V2 only
PaymentRequirements *types.PaymentRequirements // V2 only
}
HTTPProcessResult indicates the result of processing a payment request
type HTTPRequestContext ¶
type HTTPRequestContext struct {
Adapter HTTPAdapter
Path string
Method string
PaymentHeader string
}
HTTPRequestContext encapsulates an HTTP request
type HTTPResponseInstructions ¶
type HTTPResponseInstructions struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Body interface{} `json:"body,omitempty"`
IsHTML bool `json:"isHtml,omitempty"`
}
HTTPResponseInstructions tells the framework how to respond
type HTTPServer ¶
type HTTPServer = x402HTTPResourceServer
HTTPServer is an alias for x402HTTPResourceServer
type PaymentOption ¶
type PaymentOption struct {
Scheme string `json:"scheme"`
PayTo interface{} `json:"payTo"` // string or DynamicPayToFunc
Price interface{} `json:"price"` // x402.Price or DynamicPriceFunc
Network x402.Network `json:"network"`
MaxTimeoutSeconds int `json:"maxTimeoutSeconds,omitempty"`
Extra map[string]interface{} `json:"extra,omitempty"`
}
PaymentOption represents a single payment option for a route Represents one way a client can pay for access to the resource
type PaymentOptions ¶
type PaymentOptions = []PaymentOption
PaymentOptions is a slice of PaymentOption for convenience
type PaymentRoundTripper ¶
type PaymentRoundTripper struct {
Transport http.RoundTripper
// contains filtered or unexported fields
}
PaymentRoundTripper implements http.RoundTripper with x402 payment handling
type PaywallConfig ¶
type PaywallConfig struct {
AppName string `json:"appName,omitempty"`
AppLogo string `json:"appLogo,omitempty"`
CurrentURL string `json:"currentUrl,omitempty"`
Testnet bool `json:"testnet,omitempty"`
}
PaywallConfig configures the HTML paywall for browser requests
type ProcessSettleResult ¶
type ProcessSettleResult struct {
Success bool
Headers map[string]string
ErrorReason string
Transaction string
Network x402.Network
Payer string
}
ProcessSettleResult represents the result of settlement processing
type RouteConfig ¶
type RouteConfig struct {
// Payment options for this route
Accepts PaymentOptions `json:"accepts"`
// HTTP-specific metadata
Resource string `json:"resource,omitempty"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
CustomPaywallHTML string `json:"customPaywallHtml,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
// UnpaidResponseBody is an optional callback to generate a custom response for unpaid API requests.
// For browser requests (Accept: text/html), the paywall HTML takes precedence.
// If not provided, defaults to { ContentType: "application/json", Body: nil }.
UnpaidResponseBody UnpaidResponseBodyFunc `json:"-"`
}
RouteConfig defines payment configuration for an HTTP endpoint
type RoutesConfig ¶
type RoutesConfig map[string]RouteConfig
RoutesConfig maps route patterns to configurations
type UnpaidResponse ¶
type UnpaidResponse struct {
// ContentType is the content type for the response (e.g., "application/json", "text/plain").
ContentType string
// Body is the response body to include in the 402 response.
Body interface{}
}
UnpaidResponse represents the custom response for unpaid (402) API requests. This allows servers to return preview data, error messages, or other content when a request lacks payment.
type UnpaidResponseBodyFunc ¶
type UnpaidResponseBodyFunc func(ctx context.Context, reqCtx HTTPRequestContext) (*UnpaidResponse, error)
UnpaidResponseBodyFunc generates a custom response for unpaid API requests. It receives the HTTP request context and returns the content type and body for the 402 response.
For browser requests (Accept: text/html), the paywall HTML takes precedence. This callback is only used for API clients.
Args:
ctx: Context for cancellation reqCtx: HTTP request context
Returns:
UnpaidResponse with ContentType and Body for the 402 response