##Release Notes - HTTP Client Package v1.0
Release Date: December 15, 2024
I am excited to announce the release of version v1.0 of the HTTP Client package. This package brings new features, improvements, and enhancements to provide more flexibility and control when making HTTP requests in Go.
-
New Features
Custom HTTP Transport: The package now supports configuring a custom http.RoundTripper. This allows you to implement fine-grained control over the HTTP request/response lifecycle, including support for custom load balancing, logging, and more. -
Proxy Support: You can now configure an HTTP proxy for routing all requests through a specific server. This feature is especially useful for environments requiring specific network routing.
-
TLS/SSL Configuration: We’ve added the ability to configure custom TLS settings for secure communication. This includes options for disabling SSL verification (useful for testing environments).
-
Request/Response Body Logging: New logging options allow you to log the full request and response bodies. This is useful for debugging, but please be cautious as this may expose sensitive data in production environments.
-
Custom User-Agent Header: The package now supports setting a global User-Agent header. This ensures that all requests made by the client carry a custom user-agent, providing better identification for your API requests.
-
Enhancements
Retries with Delay: Automatic retries on failed requests have been improved. You can now configure both the retry count and the delay between retries for enhanced reliability in unreliable network conditions. -
Logging: Request and response logs are more detailed, providing visibility into the headers and bodies of requests/responses when enabled. This is invaluable for debugging and performance monitoring.
-
Timeout Configuration: The default timeout for requests has been set to 30 seconds, but it is fully configurable. You can now easily adjust it based on your application's needs.
-
How to Get
go get github.com/yourusername/httpclient@v1.0Example Usage
Here’s how you can create a custom HTTP client with retry logic, logging, and proxy configuration:
package main
import (
"fmt"
"log"
"time"
"github.com/srahkmli/httpclient"
)
func main() {
// Create a new HTTP client with custom options
client := httpclient.New(
httpclient.WithTimeout(5*time.Second),
httpclient.WithRetries(3, 2*time.Second),
httpclient.WithLogging(true),
httpclient.WithUserAgent("MyCustomUserAgent/1.0"),
httpclient.WithBodyLogging(true),
httpclient.WithProxy("http://proxy.example.com"),
)
// Make a GET request
response, err := client.GetRequest(context.Background(), "https://api.example.com/data", nil)
if err != nil {
log.Fatalf("Error making GET request: %v", err)
}
// Print the response
fmt.Println("Response:", string(response))
}License
This project is licensed under the MIT License. See the LICENSE file for details.