A Go library that provides a rate-limited HTTP client to simplify working with rate-limited APIs.
Many APIs impose rate limits to prevent abuse and ensure fair usage. Implementing proper rate limiting in client applications can be complex and error-prone. The HTTP Rate-Limited Client (RLC) handles this complexity for you by:
- Enforcing a configurable maximum number of requests per second
- Automatically retrying failed requests with exponential backoff
- Handling rate limit responses (HTTP 429) with appropriate waiting periods
- Providing a simple, thread-safe interface for making HTTP requests
go get github.com/oglofus/http-rlcRequires Go 1.24 or later.
package main
import (
"fmt"
"github.com/oglofus/http-rlc"
)
func main() {
// Create a new client with a limit of 5 requests per second
client := http_rlc.NewRateLimitedClient(5)
// Make a GET request
headers := map[string]string{
"Authorization": "Bearer your-token",
}
response, err := client.Get("https://api.example.com/resource", headers)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(string(response))
}package main
import (
"fmt"
"strings"
"github.com/oglofus/http-rlc"
)
func main() {
client := http_rlc.NewRateLimitedClient(5)
// Create a request body
jsonBody := `{"key": "value"}`
body := strings.NewReader(jsonBody)
// Set headers
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": "Bearer your-token",
}
// Make a POST request
response, err := client.Post("https://api.example.com/resource", body, headers)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(string(response))
}- Rate Limiting: Enforces a maximum number of requests per second
- Automatic Retries: Retries failed requests with exponential backoff
- Rate Limit Handling: Automatically handles 429 responses by waiting and retrying
- Thread Safety: Safe for concurrent use across multiple goroutines
- Simple Interface: Easy-to-use methods for common HTTP operations
- Zero Dependencies: Uses only the Go standard library
This project is licensed under the BSD 3-Clause License — see the LICENSE file for details.
Copyright (c) 2025, Oglofus Ltd (Company No. 14840351)