github.com/slashdevops/httpx
Package httpx provides comprehensive utilities for building and executing HTTP requests with advanced features including fluent request building, automatic retry logic, and type-safe generic clients. Requirements: Go 1.22 or higher is required to use this package. Zero Dependencies: This package is built entirely using the Go standard library, with no external dependencies. This ensures maximum reliability, security, and minimal maintenance overhead for your projects. This package is designed to simplify HTTP client development in Go by providing: Build and execute a simple GET request: Use type-safe generic client: The RequestBuilder provides a fluent API for constructing HTTP requests with comprehensive input validation and error accumulation. All inputs are validated before the request is built, ensuring early error detection. Basic usage: Request builder features: Validation features: The builder validates all inputs and accumulates errors, allowing you to detect multiple issues at once: Builder reuse: The GenericClient provides type-safe HTTP requests using Go generics with automatic JSON marshaling and unmarshaling. This eliminates the need for manual type assertions and reduces boilerplate code. Basic usage: Generic client features: Configuration options: Integration with RequestBuilder: Multiple typed clients: Error handling: The package provides transparent retry logic that automatically retries failed requests using configurable backoff strategies. Retry logic preserves all request properties including headers and authentication. What gets retried: What does NOT get retried: Available retry strategies: Exponential Backoff (recommended for most use cases): strategy := httpx.ExponentialBackoff(500*time.Millisecond, 10*time.Second) // Wait times: 500ms → 1s → 2s → 4s → 8s (capped at maxDelay) Fixed Delay (useful for predictable retry timing): strategy := httpx.FixedDelay(1*time.Second) // Wait times: 1s → 1s → 1s Jitter Backoff (prevents thundering herd problem): strategy := httpx.JitterBackoff(500*time.Millisecond, 10*time.Second) // Wait times: random(0-500ms) → random(0-1s) → random(0-2s) Direct usage (advanced): The ClientBuilder provides a fluent API for configuring HTTP clients with retry logic, timeouts, and connection pooling. All settings are validated and default to production-ready values if out of range. Basic configuration: Advanced configuration: Combine with GenericClient: Default values (validated and adjusted if out of range): The package provides comprehensive error handling with specific error types: ErrorResponse (from GenericClient): Structured API errors with status code and message ClientError: Generic HTTP client operation errors RequestBuilder validation errors: Accumulated during building, reported at Build() time Error handling examples: Use type-safe clients for JSON APIs: client := httpx.NewGenericClient[User](...) response, err := client.Get("/users/1") // response.Data is User, not interface{} Configure retry logic for production: retryClient := httpx.NewClientBuilder(). WithMaxRetries(3). WithRetryStrategy(httpx.ExponentialBackoffStrategy). Build() Reuse HTTP clients (they're safe for concurrent use): client := httpx.NewGenericClient[User](...) // Use from multiple goroutines safely Use contexts for timeouts and cancellation: ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() req, _ := builder.WithContext(ctx).Build() Validate before building: if builder.HasErrors() { // Handle validation errors } Handle API errors appropriately: if apiErr, ok := err.(*httpx.ErrorResponse); ok { // Handle specific status codes } The package provides comprehensive proxy support for all HTTP clients. Proxy configuration works transparently across all client types and supports both HTTP and HTTPS proxies with optional authentication. Basic proxy configuration with ClientBuilder: HTTPS proxy: Proxy with authentication: Proxy with GenericClient: Proxy with retry client: Disable proxy (override environment variables): Common proxy ports: The proxy configuration: All utilities in this package are safe for concurrent use across multiple goroutines: Example concurrent usage: The package uses slog for debug logging. Enable debug logging to see: Enable debug logging: You can view the full documentation and examples locally by running: Then navigate to http://localhost:8080/pkg/github.com/slashdevops/httpx/ in your browser to browse the complete documentation, examples, and source code. For complete examples and API reference, see the README.md file or visit: https://pkg.go.dev/github.com/slashdevops/httpx Example demonstrates using exponential backoff. Example_withLogger_disabled demonstrates the default behavior with no logging. This example shows that by default, logging is disabled for clean, silent operation.
proxy.golang.org
v0.0.4
5 days ago
4
Past Dependents
Check this option to include packages that no longer depend on this package in their latest version but previously did.
Filter
Filter by Kind
Links
| Registry | proxy.golang.org |
| Source | Repository |
| Docs | Documentation |
| JSON API | View JSON |
| CodeMeta | codemeta.json |
Package Details
| PURL |
pkg:golang/github.com/slashdevops/httpx
spec |
| License | Apache-2.0 |
| Namespace | github.com/slashdevops |
| First Release | about 2 months ago |
| Last Synced | about 10 hours ago |