hq-go-http
is a Go (Golang) HTTP client package, designed for robust web communication. It is built with retry policies, digest authentication support, and automatic fallback to HTTP/2, offering a highly resilient solution for making HTTP requests.
- Retry Logic: Automatically retries failed requests based on customizable rules. You can define how many times to retry, how long to wait between retries, and how the wait time should increase.
- Digest Authentication: Supports digest authentication, a security mechanism used in some web services, to ensure safe and secure communication.
- HTTP/2 Fallback: If an HTTP/1.x request fails, the client can automatically retry the request over HTTP/2.
- Timeout and Error Handling: Configurable timeouts to avoid hanging requests, and custom error handlers to gracefully manage failures.
- Idle Connection Management: Efficient management of idle connections to reduce unnecessary resource consumption.
To install the package, run the following command in your terminal:
go get -v -u github.com/hueristiq/hq-go-http
This command will download and install the hq-go-http
package into your Go workspace, making it available for use in your projects.
Here's a simple example demonstrating how to use hq-go-http
:
package main
import (
"log"
http "github.com/hueristiq/hq-go-http"
)
func main() {
client := http.NewClient(&http.ClientConfiguration{
RetryMax: 3, // Max number of retries
Timeout: 10 * time.Second, // Request timeout
RetryWaitMin: 1 * time.Second, // Minimum wait between retries
RetryWaitMax: 5 * time.Second, // Maximum wait between retries
})
response, err := client.Get("https://example.com")
if err != nil {
log.Fatalf("Request failed: %v", err)
}
defer response.Body.Close()
// Handle response here
}
We welcome contributions! Feel free to submit Pull Requests or report Issues. For more details, check out the contribution guidelines.
This package is licensed under the MIT license. You are free to use, modify, and distribute it, as long as you follow the terms of the license. You can find the full license text in the repository - Full MIT license text.
A huge thanks to all the contributors who have helped make hq-go-http
what it is today!
If you're interested in more packages like this, check out:
Hashicorp's go-retryablehttp ◇ Project Discovery's retryablehttp-go ◇ Gojek's heimdall ◇ Monaco's request ◇ Opus Domini's fast-shot