http

package
v0.0.0-...-7012119 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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

View Source
const (
	ResultNoPaymentRequired = "no-payment-required"
	ResultPaymentVerified   = "payment-verified"
	ResultPaymentError      = "payment-error"
)

Result type constants

View Source
const DefaultFacilitatorURL = "https://x402.org/facilitator"

DefaultFacilitatorURL is the default public facilitator

View Source
const EVMPaywallTemplate = "" /* 1928510-byte string literal not displayed */

EVMPaywallTemplate is the pre-built EVM paywall template with inlined CSS and JS

View Source
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 Do

func Do(ctx context.Context, req *http.Request, x402Client *x402HTTPClient) (*http.Response, error)

Do performs an HTTP request with automatic payment handling

func Get

func Get(ctx context.Context, url string, x402Client *x402HTTPClient) (*http.Response, error)

Get performs a GET request with automatic payment handling

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

func WrapClient(client *http.Client, x402Client *x402HTTPClient) *http.Client

WrapClient wraps a standard HTTP client with x402 payment handling

func WrapHTTPClientWithPayment

func WrapHTTPClientWithPayment(client *http.Client, x402Client *x402HTTPClient) *http.Client

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

type DynamicPriceFunc func(context.Context, HTTPRequestContext) (x402.Price, error)

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 HTTPClient

type HTTPClient = x402HTTPClient

HTTPClient is an alias for x402HTTPClient

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

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

func (*PaymentRoundTripper) RoundTrip

func (t *PaymentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper with V1/V2 version detection

type PaywallConfig

type PaywallConfig struct {
	AppName    string `json:"appName,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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL