{"id":28289830,"url":"https://github.com/dillonstreator/request","last_synced_at":"2025-06-13T06:31:46.097Z","repository":{"id":61625169,"uuid":"539680297","full_name":"dillonstreator/request","owner":"dillonstreator","description":"golang http request library","archived":false,"fork":false,"pushed_at":"2022-10-10T21:11:21.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-22T02:11:40.878Z","etag":null,"topics":["http","http-client","json-api"],"latest_commit_sha":null,"homepage":"","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/dillonstreator.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}},"created_at":"2022-09-21T20:50:27.000Z","updated_at":"2023-03-13T00:26:09.000Z","dependencies_parsed_at":"2022-10-19T18:45:34.910Z","dependency_job_id":null,"html_url":"https://github.com/dillonstreator/request","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dillonstreator/request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Frequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Frequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Frequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Frequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dillonstreator","download_url":"https://codeload.github.com/dillonstreator/request/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Frequest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259594227,"owners_count":22881624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["http","http-client","json-api"],"created_at":"2025-05-22T02:11:28.942Z","updated_at":"2025-06-13T06:31:46.087Z","avatar_url":"https://github.com/dillonstreator.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# request\n\ngo request library for http apis\n\n## Installation\n\n```bash\ngo get github.com/dillonstreator/request\n```\n\n## Usage\n\n```go\nclient := request.NewClient(\"https://jsonplaceholder.typicode.com/todos\")\n\ntodos := []struct {\n    ID        int    `json:\"id\"`\n    UserID    int    `json:\"userId\"`\n    Title     string `json:\"title\"`\n    Completed bool   `json:\"completed\"`\n}{}\n\nvalues := url.Values{}\nvalues.Add(\"userId\", \"2\")\n\nheaders := http.Header{}\n\nres, err := client.Get(context.Background(), \"/\", headers, values, \u0026todos)\nif err != nil {\n    log.Fatal(err)\n}\n\nfmt.Println(res)\nfmt.Println(todos)\n```\n\n### Custom http client\n\n```go\nhttpClient := \u0026http.Client{\n    Timeout: time.Second * 5,\n}\n\nclient := request.NewClient(\n    \"https://jsonplaceholder.typicode.com/todos\",\n    request.WithHTTPClient(httpClient),\n)\n```\n\n### Custom error handling\n\n```go\ntype CustomError struct {\n\tDetail string `json:\"detail\"`\n}\n\nfunc (c *CustomError) Error() string {\n\treturn fmt.Sprintf(\"custom error details: %s\", c.Detail)\n}\n\nclient := request.NewClient(\n    \"https://jsonplaceholder.typicode.com/todos\",\n    request.WithErrChecker(func(req *http.Request, res *http.Response) error {\n        if res.StatusCode != http.StatusOK { // your custom error handling here...\n            b, err := io.ReadAll(res.Body)\n            if err != nil {\n                return err\n            }\n\n            custErr := \u0026CustomError{}\n            err = json.Unmarshal(b, custErr)\n            if err != nil {\n                return err\n            }\n\n            return custErr\n        }\n\n        return nil\n    }),\n)\n\nitems := []struct {\n    // ...\n}{}\n_, err := client.Get(context.Background(), \"/\", nil, nil, \u0026items)\nif err != nil {\n    if custErr, ok := err.(*CustomError); ok {\n        log.Fatal(custErr.Detail)\n    }\n}\n\nfmt.Println(items)\n```\n\n### Token auth\n\n```go\nclient := request.NewClient(\n    \"https://some-token-authed-api.com\",\n    request.WithTokenAuth(\"Bearer \u003ctoken-here\u003e\"),\n)\nclient = request.NewClient(\n    \"https://some-token-authed-api.com\",\n    request.WithTokenAuth(\"Token \u003ctoken-here\u003e\"),\n)\nclient = request.NewClient(\n    \"https://some-token-authed-api.com\",\n    request.WithTokenAuth(\"\u003ctoken-here\u003e\"),\n)\n```\n\n### Basic auth\n\n```go\nclient := request.NewClient(\n    \"https://some-basic-authed-api.com\",\n    request.WithBasicAuth(\"user\", \"pass\"),\n)\n```\n\n### All together\n\n```go\ncustomHTTPClient := \u0026http.Client{\n    Timeout: time.Second * 5,\n}\n\nclient := request.NewClient(\n    \"https://some-token-authed-api.com\",\n    request.WithHTTPClient(customHTTPClient),\n    request.WithTokenAuth(\"Bearer \u003ctoken-here\u003e\"),\n    request.WithErrChecker(func(req *http.Request, res *http.Response) error {\n        if res.StatusCode != http.StatusOK {\n            return fmt.Errorf(\"some error occurred %d %s%s\", res.StatusCode, req.URL.Host, req.URL.Path)\n        }\n\n        return nil\n    }),\n)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdillonstreator%2Frequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdillonstreator%2Frequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdillonstreator%2Frequest/lists"}