{"id":39709739,"url":"https://github.com/bearaujus/bhttp","last_synced_at":"2026-01-18T10:37:18.398Z","repository":{"id":332979370,"uuid":"1135624988","full_name":"bearaujus/bhttp","owner":"bearaujus","description":"Minimal HTTP client helper for Go (Automatic JSON unwrapping, simple retries, rate limiting)","archived":false,"fork":false,"pushed_at":"2026-01-17T03:43:33.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-17T05:23:11.428Z","etag":null,"topics":["go","golang","golang-library","http"],"latest_commit_sha":null,"homepage":"https://github.com/bearaujus/bhttp","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bearaujus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-16T11:09:32.000Z","updated_at":"2026-01-17T03:43:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bearaujus/bhttp","commit_stats":null,"previous_names":["bearaujus/bhttp"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bearaujus/bhttp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearaujus%2Fbhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearaujus%2Fbhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearaujus%2Fbhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearaujus%2Fbhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bearaujus","download_url":"https://codeload.github.com/bearaujus/bhttp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bearaujus%2Fbhttp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28534530,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","golang-library","http"],"created_at":"2026-01-18T10:37:18.303Z","updated_at":"2026-01-18T10:37:18.387Z","avatar_url":"https://github.com/bearaujus.png","language":"Go","readme":"# BHTTP - Minimal HTTP Client Helper for Go (Automatic JSON Unwrapping, Simple Retries, Rate Limiting)\n\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bearaujus/bhttp)](https://goreportcard.com/report/github.com/bearaujus/bhttp)\n\nBHTTP is a lightweight Go library that wraps `net/http`. This library is able to validate expected status codes, \nretry on specific status codes, optionally rate limit requests, and decode JSON responses into a destination struct.\n\n## Installation\n\nTo install BHTTP, run:\n\n```sh\ngo get github.com/bearaujus/bhttp\n```\n\n## Import\n\n```go\nimport \"github.com/bearaujus/bhttp\"\n```\n\n## Features\n\n- Validate response status codes (defaults to `200` OK).\n- Retry on specific response status codes (e.g., `429`, `500`, `502`, `503`, `504`).\n- Optional rate limiting using `golang.org/x/time/rate`.\n- Decode JSON responses into a struct (DoAndUnwrap).\n- Helpful error messages including response body (pretty-printed if JSON).\n\n## Usage\n\n### 1. Simple \"send + unwrap\"\n\n```go\ntype HttpBinGetResponse struct {\n    URL     string            `json:\"url\"`\n    Headers map[string]string `json:\"headers\"`\n}\n\nfunc main() {\n    req, _ := http.NewRequest(http.MethodGet, \"https://httpbin.org/get\", nil)\n\n    // BHTTP will automatically unmarshal the JSON response body into HttpBinGetResponse struct.\n    resp, err := bhttp.DoAndUnwrap[HttpBinGetResponse](req)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"[%T] %+v\\n\", resp, resp)\n}\n```\n\n```text\n[*main.HttpBinGetResponse] \u0026{URL:https://httpbin.org/get Headers:map[Accept-Encoding:gzip Host:httpbin.org User-Agent:Go-http-client/2.0]}\n```\n\n### 2. Use Options to validate expected status codes.\n```go\nfunc main() {\n    req, _ := http.NewRequest(http.MethodGet, \"https://httpbin.org/get\", nil)\n\n    opts := \u0026bhttp.Options{\n        // Only treat these status codes as success (defaults to 200 if omitted). \n        ExpectedStatusCodes: []int{http.StatusOK},\n    }\n    \n    var out HttpBinGetResponse\n    if err := bhttp.New().DoAndUnwrapWithOptions(req, \u0026out, opts); err != nil {\n        panic(err)\n    }\n\n    fmt.Printf(\"[%T] %+v\\n\", resp, resp)\n}\n```\n\n```text\n[main.HttpBinGetResponse] {URL:https://httpbin.org/get Headers:map[Accept-Encoding:gzip Host:httpbin.org User-Agent:Go-http-client/2.0]}\n```\n\n### 3. Use Options + Retry to retry on specific status codes (e.g., 429 / 5xx).\n```go\nfunc main() {\n    // Using httpstat.us to simulate a retryable status.\n    req, _ := http.NewRequest(http.MethodGet, \"https://httpstat.us/503\", nil)\n    \n    opts := \u0026bhttp.Options{\n        ExpectedStatusCodes: []int{http.StatusOK},\n        Retry: \u0026bhttp.RetryConfig{\n            // Number of retries AFTER the first attempt (total tries = 1 + Attempts).\n            Attempts: 2,\n            \n            // Retry only when the response status code matches one of these.\n            RetryStatusCodes: []int{http.StatusTooManyRequests, http.StatusServiceUnavailable},\n        },\n    }\n    \n    // Note: On the final attempt, BHTTP will stop treating these as retryable so you get\n    // a real error with the response body if it still fails.\n    if err := bhttp.DoWithOptions(req, opts); err != nil {\n        panic(err)\n    }\n}\n```\n\n```text\npanic: retries exhausted after 2 attempt(s): Get \"https://httpstat.us/503\": EOF\n```\n\n## TODO\n- Add support for back-off retry, jitter \u0026 similar kind of components for retry mechanism\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/bearaujus/bhttp/blob/master/LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbearaujus%2Fbhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbearaujus%2Fbhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbearaujus%2Fbhttp/lists"}