The httpc
package is a robust HTTP client for Go, equipped with features such as retry logic, custom headers, form values, and basic authentication settings. It utilizes a retryable transport structure to manage request retries effectively, enhancing the reliability of HTTP requests in Go applications.
opts := []httpc.HttpClientOptions{
httpc.WithMaxRetries(3),
httpc.WithMaxRetryWait(3), //seconds
}
client := httpc.NewHttpClient(opts...)
URL : = "https://thiagozs.com"
resp, err := client.Get(URL)
if err != nil {
fmt.Printf("error: %+v\n",err)
return
}
- RetryableTransport: Manages the retry logic for HTTP requests with configurable retry counts and wait times.
- HttpClient: A thread-safe HTTP client with methods to perform various HTTP requests and manage request headers, form values, and basic authentication settings.
Initializes a new HttpClient instance with specified options.
Sends a GET request to the specified address and returns the response body as a byte slice.
Sends a POST request to the specified address with the provided payload and returns the response body as a byte slice.
Sends a PUT request to the specified address with the provided payload and returns the response body as a byte slice.
Sends a DELETE request to the specified address with the provided payload and returns the response body as a byte slice.
Sends a PATCH request to the specified address with the provided payload and returns the response body as a byte slice.
Sends a HEAD request to the specified address and returns the full http.Response object.
Sets or updates a header for a specified HTTP method.
Deletes a header for a specified HTTP method.
Sets or updates a form value for a specified HTTP method.
Deletes a form value for a specified HTTP method.
Retrieves all form values set for a specified HTTP method.
Sets the Basic Authentication for a specified HTTP method.
Retrieves the Basic Authentication set for a specified HTTP method.
Sets or updates a header specifically for PATCH requests.
Retrieves all headers set for a specified HTTP method.
Refer to the source code for detailed usage and examples.
Our version numbers adhere to the semantic versioning specification. You can explore the available versions by checking the tags on this repository. For more details about our license model, please refer to the LICENSE file.
© 2023, thiagozs.