{"id":13764070,"url":"https://github.com/zpatrick/rclient","last_synced_at":"2026-01-14T14:25:27.940Z","repository":{"id":57481078,"uuid":"83373783","full_name":"zpatrick/rclient","owner":"zpatrick","description":"Minimalistic REST client for Go applications","archived":false,"fork":false,"pushed_at":"2019-11-28T00:03:52.000Z","size":30,"stargazers_count":35,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-10T17:41:35.281Z","etag":null,"topics":["awesome-go","client","go","golang","rest"],"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/zpatrick.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":"2017-02-28T01:07:25.000Z","updated_at":"2022-12-24T03:03:55.000Z","dependencies_parsed_at":"2022-09-26T17:41:24.962Z","dependency_job_id":null,"html_url":"https://github.com/zpatrick/rclient","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zpatrick/rclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zpatrick","download_url":"https://codeload.github.com/zpatrick/rclient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zpatrick%2Frclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28422958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["awesome-go","client","go","golang","rest"],"created_at":"2024-08-03T15:01:11.883Z","updated_at":"2026-01-14T14:25:27.916Z","avatar_url":"https://github.com/zpatrick.png","language":"Go","readme":"# RClient\n\n[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/zpatrick/rclient/blob/master/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/zpatrick/rclient)](https://goreportcard.com/report/github.com/zpatrick/rclient)\n[![Go Doc](https://godoc.org/github.com/zpatrick/rclient?status.svg)](https://godoc.org/github.com/zpatrick/rclient)\n\n## Getting Started\nCheckout the [Examples](https://github.com/zpatrick/rclient/tree/master/examples) folder for some working examples.\nThe following snippet shows RClient interacting with Github's API:\n```\npackage main\n\nimport (\n        \"github.com/zpatrick/rclient\"\n        \"log\"\n)\n\ntype Repository struct {\n        Name        string `json:\"name\"`\n}\n\nfunc main() {\n        client := rclient.NewRestClient(\"https://api.github.com\")\n\n        var repos []Repository\n        if err := client.Get(\"/users/zpatrick/repos\", \u0026repos); err != nil {\n                log.Fatal(err)\n        }\n\n        log.Println(repos)\n}\n```\n\n## Request Options\nRequests can be configured using a [Request Option](https://godoc.org/github.com/zpatrick/rclient#RequestOption).\nA `RequestOption` is simply a function that manipulates an `http.Request`.\nYou can create request options like so:\n```\nsetProto := func(req *http.Request) error {\n    req.Proto = \"HTTP/1.0\"\n    return nil\n}\n\nclient.Get(\"/path\", \u0026v, setProto)\n```\n\nThe built-in request options are described below.\n\n#### Header / Headers\nThe `Header()` and `Headers()` options add header(s) to a `*http.Request`.\n```\n// add a single header\nclient.Get(\"/path\", \u0026v, rclient.Header(\"name\", \"val\"))\n\n// add multiple headers\nclient.Get(\"/path\", \u0026v, rclient.Header(\"name1\", \"val1\"), rclient.Header(\"name2\", \"val2\"))\nclient.Get(\"/path\", \u0026v, rclient.Headers(map[string]string{\"name1\": \"val1\", \"name2\":\"val2\"}))\n```\n\n#### Basic Auth\nThe `BasicAuth()` option adds basic auth to a `*http.Request`.\n```\nclient.Get(\"/path\", \u0026v, rclient.BasicAuth(\"user\", \"pass\"))\n```\n\n#### Query\nThe `Query()` options adds a query to a `*http.Request`.\n```\nquery := url.Values{}\nquery.Add(\"name\", \"John\")\nquery.Add(\"age\", \"35\")\n\nclient.Get(\"/path\", \u0026v, rclient.Query(query))\n```\n\n**NOTE**: This can also be accomplished by adding the raw query to the `path` argument\n```\nclient.Get(\"/path?name=John\u0026age=35\", \u0026v)\n```\n\n## Client Configuration\nThe `RestClient` can be configured using the [Client Options](https://godoc.org/github.com/zpatrick/rclient#ClientOption) described below.\n\n#### Doer\nThe `Doer()` option sets the `RequestDoer` field on the `RestClient`. \nThis is the `http.DefaultClient` by default, and it can be set to anything that satisfies the [RequestDoer](https://godoc.org/github.com/zpatrick/rclient#RequestDoer) interface. \n```\nclient, err := rclient.NewRestClient(\"https://api.github.com\", rclient.Doer(\u0026http.Client{}))\n```\n\n#### Request Options\nThe `RequestOptions()` option sets the `RequestOptions` field on the `RestClient`.\nThis will manipulate each request made by the `RestClient`.\nThis can be any of the options described in the [Request Options](#request-options) section. \nA typical use-case would be adding headers for each request.\n```\noptions := []rclient.RequestOption{\n    rclient.Header(\"name\", \"John Doe\").\n    rclient.Header(\"token\", \"abc123\"),\n}\n\nclient, err := rclient.NewRestClient(\"https://api.github.com\", rclient.RequestOptions(options...))\n```\n\n#### Builder\nThe `Builder()` option sets the `RequestBuilder` field on the `RestClient`.\nThis field is responsible for building `*http.Request` objects. \nThis is the [BuildJSONRequest](https://godoc.org/github.com/zpatrick/rclient#BuildJSONRequest) function by default, and it can be set to any [RequestBuilder](https://godoc.org/github.com/zpatrick/rclient#RequestBuilder) function.\n```\nbuilder := func(method, url string, body interface{}, options ...RequestOption) (*http.Request, error){\n    req, _ := http.NewRequest(method, url, nil)\n    for _, option := range options {\n\t\tif err := option(req); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\t\n    return nil, errors.New(\"I forgot to add a body to the request!\")\n}\n\nclient, err := rclient.NewRestClient(\"https://api.github.com\", rclient.Builder(builder))\n```\n\n#### Reader\nThe `Reader()` option sets the `ResponseReader` field on the `RestClient`.\nThis field is responsible for reading `*http.Response` objects. \nThis is the [ReadJSONResponse](https://godoc.org/github.com/zpatrick/rclient#ReadJSONResponse) function by default, and it can be set to any [ResponseReader](https://godoc.org/github.com/zpatrick/rclient#ResponseReader) function.\n```\nreader := func(resp *http.Response, v interface{}) error{\n    defer resp.Body.Close()\n    return json.NewDecoder(resp.Body).Decode(v)\n}\n\nclient, err := rclient.NewRestClient(\"https://api.github.com\", rclient.Reader(reader))\n```\n\n# License\nThis work is published under the MIT license.\n\nPlease see the `LICENSE` file for details.\n","funding_links":[],"categories":["实用工具","Utilities","工具库","公用事业公司","工具库`可以提升效率的通用代码库和工具`","實用工具","Utility"],"sub_categories":["Advanced Console UIs","HTTP Clients","Utility/Miscellaneous","查询语","交流","实用程序/Miscellaneous","高級控制台界面","Fail injection","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzpatrick%2Frclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzpatrick%2Frclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzpatrick%2Frclient/lists"}