Skip to content

Releases: ubgo/httpreq

Release list

v0.2.0

Choose a tag to compare

@khanakia khanakia released this 03 Jul 15:28

Zero-dependency, stdlib-only. This release turns httpreq from a bare JSON convenience into a complete small HTTP client while keeping the tiny surface and zero deps.

Highlights

Observability (dependency-free)

  • WithObserver(func(ctx, Trace)) — one Trace per attempt on every path (success, non-2xx, network error, decode error); metadata only, no bodies or headers.
  • WithConnTrace() — DNS/Connect/TLS/TTFB phase timing via net/http/httptrace.
  • SlogObserver(*slog.Logger, level) — structured logging via stdlib log/slog; failures log at ERROR.

Dump as curl

  • Curl(ctx, url, opts...) returns the request as a runnable curl command without sending; WithCurl(func(string)) logs exactly what Do sends; RequestCurl(*http.Request) renders any request. Headers sorted, shell-quoted, body read without being consumed.

Auth & bodies

  • WithBasicAuth, WithFormBody (x-www-form-urlencoded), WithUserAgent + default httpreq/<version>.

Responses

  • WithResponseBytes(*[]byte) — capture raw non-JSON bodies.
  • WithResponseWriter(io.Writer) — stream large downloads without buffering.
  • WithErrorInto(any) — decode a structured error body on non-2xx.
  • WithExpectStatus(...int) — treat 304 etc. as success.

Escape hatch & bulk setters

  • WithRequest(func(*http.Request) error) — sign/mutate the built request before send (also runs for Curl).
  • WithHeaders(http.Header), WithQuery(url.Values).

100% test coverage, race-clean, lint-clean. See the CHANGELOG for the full list.

Full changelog: v0.1.0...v0.2.0