{"id":22332742,"url":"https://github.com/xgfone/go-http-client","last_synced_at":"2025-10-12T04:39:47.662Z","repository":{"id":40043730,"uuid":"392750121","full_name":"xgfone/go-http-client","owner":"xgfone","description":"A chained go HTTP client.","archived":false,"fork":false,"pushed_at":"2025-08-01T10:37:31.000Z","size":96,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-01T12:51:38.012Z","etag":null,"topics":["client","go-client","go-http-client","http-client","http-request","httpclient","request"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xgfone.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}},"created_at":"2021-08-04T16:03:45.000Z","updated_at":"2025-08-01T10:37:02.000Z","dependencies_parsed_at":"2025-04-20T07:29:25.666Z","dependency_job_id":null,"html_url":"https://github.com/xgfone/go-http-client","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/xgfone/go-http-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/go-http-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-http-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010272,"owners_count":26084720,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["client","go-client","go-http-client","http-client","http-request","httpclient","request"],"created_at":"2024-12-04T04:19:36.630Z","updated_at":"2025-10-12T04:39:47.612Z","avatar_url":"https://github.com/xgfone.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A chained go HTTP client\n[![Build Status](https://github.com/xgfone/go-http-client/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-http-client/actions/workflows/go.yml)\n[![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-http-client)](https://pkg.go.dev/github.com/xgfone/go-http-client)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-http-client/master/LICENSE)\n![Minimum Go Version](https://img.shields.io/github/go-mod/go-version/xgfone/go-http-client?label=Go%2B)\n![Latest SemVer](https://img.shields.io/github/v/tag/xgfone/go-http-client?sort=semver)\n\n\n## Install\n\n```shell\n$ go get -u github.com/xgfone/go-http-client\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\thttpclient \"github.com/xgfone/go-http-client\"\n)\n\nfunc main() {\n\t// Create a new HTTP Client instead of the default.\n\tclient := httpclient.Clone().\n\t\tSetContentType(\"application/json\").\n\t\tAddAccept(\"application/json\")\n\n\t// (Optional): Set other options.\n\t// client.\n\t//     SetReqBodyEncoder(httpclient.EncodeData).\n\t//     SetResponseHandler2xx(responseHandler2xx).\n\t//     SetResponseHandler4xx(responseHandler4xx).\n\t//     SetResponseHandler5xx(responseHandler5xx)\n\n\tvar result struct {\n\t\tUsername string `json:\"username\"`\n\t\tPassword string `json:\"password\"`\n\t}\n\n\t// client.SetBaseURL(\"http://localhost:12345\").Get(\"/path\")\n\terr := client.Get(\"http://127.0.0.1/path\").\n\t\tAddAccept(\"application/xml\").\n\t\tAddHeader(\"X-Header1\", \"value1\").\n\t\tSetHeader(\"X-Header2\", \"value2\").\n\t\tAddQuery(\"querykey1\", \"queryvalue1\").\n\t\tSetQuery(\"querykey2\", \"queryvalue2\").\n\n\t\t// Use the encoder referring to the request header \"Content-Type\"\n\t\t// to encode the body.\n\t\tSetBody(map[string]string{\"username\": \"xgfone\", \"password\": \"123456\"}).\n\n\t\t// Also use other body types:\n\t\t// SetBody([]byte(`this is the body as the type []byte`)).\n\t\t// SetBody(\"this is the body as the type string\").\n\t\t// SetBody(bytes.NewBufferString(\"this is the body as the type io.Reader\")).\n\n\t\t// Use the decoder referring to the response header \"Content-Type\"\n\t\t// to decode the body into result.\n\t\tDo(context.Background(), \u0026result).\n\t\tUnwrap() // Close the response body and return the inner error.\n\n\tif err != nil {\n\t\tfmt.Println(err)\n\t} else {\n\t\tfmt.Println(result)\n\t}\n}\n```\n\nThere are also some convenient functions, such as `GetContext`, `PutContext`, `PostContext`, `DeleteContext`, etc.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\thttpclient \"github.com/xgfone/go-http-client\"\n)\n\nfunc main() {\n\tvar result struct {\n\t\tUsername string `json:\"username\"`\n\t\tPassword string `json:\"password\"`\n\t}\n\terr := httpclient.GetContext(context.Background(), \"http://127.0.0.1/json_data\", \u0026result)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t} else {\n\t\tfmt.Println(result)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fgo-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-http-client/lists"}