httpx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderRequestID = "X-Request-ID"

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(r *http.Request, dst any) *wserr.Error

func Do

func Do(ctx context.Context, c *http.Client, req *http.Request, retries int) (*http.Response, error)

func JSON

func JSON(w http.ResponseWriter, status int, v any)

JSON writes v as JSON with the given status code. It sets Content-Type to application/json; charset=utf-8. Encoding errors are ignored (best-effort) and must not panic.

func NewClient

func NewClient(cfg ClientConfig) *http.Client

func NewServer

func NewServer(cfg ServerConfig, h http.Handler) *http.Server

NewServer constructs an http.Server with safe default timeouts when unset. Handler is passed through as-is.

func NoContent

func NoContent(w http.ResponseWriter)

NoContent writes HTTP 204 with no body.

func RequireJSON

func RequireJSON(next http.Handler) http.Handler

RequireJSON enforces Content-Type: application/json for methods that typically carry a body (POST, PUT, PATCH). Other methods pass through.

Types

type CheckFunc

type CheckFunc func(ctx context.Context) error

type ClientConfig

type ClientConfig struct {
	Timeout time.Duration

	MaxRetries int

	Transport http.RoundTripper

	DisableRequestIDPropagation bool
}

type Health

type Health struct {
	Checks  []CheckFunc
	Timeout time.Duration
}

Health provides HTTP handlers for /healthz (liveness) and /readyz (readiness).

func NewHealth

func NewHealth(timeout time.Duration, checks ...CheckFunc) *Health

NewHealth creates a Health with the given timeout and dependency checks. If timeout <= 0, it defaults to 2 seconds.

func (*Health) Healthz

func (h *Health) Healthz(w http.ResponseWriter, r *http.Request)

Healthz is a liveness probe: the process is running.

func (*Health) Readyz

func (h *Health) Readyz(w http.ResponseWriter, r *http.Request)

Readyz is a readiness probe: dependencies are ready.

type Page

type Page[T any] struct {
	Items      []T    `json:"items"`
	NextCursor string `json:"next_cursor,omitempty"`
}

func NewPage

func NewPage[T any](items []T, nextCursor string) Page[T]

type ServerConfig

type ServerConfig struct {
	Addr string

	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
}

Jump to

Keyboard shortcuts

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