httpx

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httpx wraps net/http with a User-Agent and retry on 5xx/429 (honoring Retry-After). The client has no Timeout — use context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client adds a User-Agent and bounded retry on 5xx, 429, and network errors. Safe for concurrent use.

func New

func New(userAgent string, opts ...Option) *Client

New returns a Client with the given User-Agent and optional overrides.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends req, cloning it before adding headers and retrying transient failures with exponential backoff or the server's Retry-After. Callers must close Response.Body.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, rawURL string, dest any) error

GetJSON GETs rawURL, expects a 2xx response, and decodes the body into dest.

type Option

type Option func(*Client)

Option configures a Client.

func WithBackoff

func WithBackoff(d time.Duration) Option

WithBackoff overrides the initial retry delay (300ms). Backoff doubles between attempts unless the server sends Retry-After. Values less than or equal to zero fall back to the default.

func WithMaxAttempts

func WithMaxAttempts(n int) Option

WithMaxAttempts overrides the total attempt budget (3). Values less than 1 still perform a single request.

Jump to

Keyboard shortcuts

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