Skip to content

oglofus/http-rlc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Rate-Limited Client (RLC)

A Go library that provides a rate-limited HTTP client to simplify working with rate-limited APIs.

Overview

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

Installation

go get github.com/oglofus/http-rlc

Requires Go 1.24 or later.

Usage

Basic Example

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))
}

POST-Request Example

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))
}

Features

  • 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

License

This project is licensed under the BSD 3-Clause License — see the LICENSE file for details.

Copyright (c) 2025, Oglofus Ltd (Company No. 14840351)

About

A Go library that provides a rate-limited HTTP client to simplify working with rate-limited APIs.

Topics

Resources

License

Stars

Watchers

Forks

Languages