Go HTTPX

A small middleware-friendly HTTP client for Go with optional retry and circuit breaker integration.

Features

  • Composable Middleware: Build request pipelines on top of http.RoundTripper.
  • Retry Integration: Reuse go-foundation retry primitives when requests fail.
  • Circuit Breaker Support: Protect upstream dependencies with a shared breaker.
  • Small API Surface: Keep client construction and request execution easy to test.

Installation

go get github.com/mirkobrombin/go-httpx

Quick Start

package main

import (
    "net/http"

    "github.com/mirkobrombin/go-foundation/pkg/resiliency"
    "github.com/mirkobrombin/go-httpx/pkg/httpx"
)

func main() {
    client := httpx.New(nil, httpx.Header("User-Agent", "my-client/1.0"))
    client.WithRetry(resiliency.WithAttempts(5))

    req, err := http.NewRequest(http.MethodGet, "https://example.com", nil)
    if err != nil {
        panic(err)
    }

    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
}

Documentation

License

This project is licensed under the MIT License. See the LICENSE file for details.