{"id":21311465,"url":"https://github.com/electricbubble/xhttpclient","last_synced_at":"2025-03-15T20:42:36.127Z","repository":{"id":68957064,"uuid":"604087408","full_name":"electricbubble/xhttpclient","owner":"electricbubble","description":"Simple Go HTTP client library","archived":false,"fork":false,"pushed_at":"2023-12-20T02:15:32.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T09:46:01.882Z","etag":null,"topics":["golang","golang-library","golang-module","http-client"],"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/electricbubble.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}},"created_at":"2023-02-20T10:01:33.000Z","updated_at":"2023-02-21T15:25:19.000Z","dependencies_parsed_at":"2023-12-19T14:25:04.475Z","dependency_job_id":"4c304596-6986-4b51-9357-dd6c33fafbb7","html_url":"https://github.com/electricbubble/xhttpclient","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"4c0cb1f87d88d590bc001e1f85c8775c3d223e30"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electricbubble%2Fxhttpclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electricbubble%2Fxhttpclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electricbubble%2Fxhttpclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electricbubble%2Fxhttpclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/electricbubble","download_url":"https://codeload.github.com/electricbubble/xhttpclient/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790946,"owners_count":20348378,"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":["golang","golang-library","golang-module","http-client"],"created_at":"2024-11-21T17:18:31.078Z","updated_at":"2025-03-15T20:42:36.091Z","avatar_url":"https://github.com/electricbubble.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# X-HTTP-Client\n\n## Install\n```shell\ngo get github.com/electricbubble/xhttpclient\n```\n\n## Usage\n\n```go\nfunc ExampleXClient_Do() {\n\ttype Response struct {\n\t\tArgs struct {\n\t\t\tHello string `json:\"hello\"`\n\t\t} `json:\"args\"`\n\t}\n\n\tcli := NewClient()\n\n\tvar respHello Response\n\t_, respBody, err := cli.Do(\u0026respHello, nil,\n\t\tNewGet().\n\t\t\tPath(\"https://httpbin.org/get\").\n\t\t\tSetQuery(\"hello\", \"world\"),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"%s\\n%s\", err, respBody)\n\t}\n\n\tfmt.Println(respHello.Args.Hello)\n\t// Output:\n\t// world\n}\n\nfunc ExampleXClient_Do_unexpected_error() {\n\tcli := NewClient()\n\n\tvar respEmpty any\n\t_, _, err := cli.Do(\u0026respEmpty, nil,\n\t\tNewGet().\n\t\t\tPath(\"https://httpbin.org/status/\", \"404\"),\n\t)\n\tfmt.Println(err)\n\t// Output:\n\t// unexpected error: URL: https://httpbin.org/status/404 (404 Not Found)\n}\n\nfunc ExampleXClient_Do_wrong_resp() {\n\ttype GitHubError struct {\n\t\tMessage          string `json:\"message\"`\n\t\tDocumentationUrl string `json:\"documentation_url\"`\n\t}\n\n\tcli := NewClient().BaseURL(\"https://api.github.com\")\n\n\tvar (\n\t\trespEmpty any\n\t\trespWrong GitHubError\n\t)\n\t_, respBody, err := cli.Do(\u0026respEmpty, \u0026respWrong,\n\t\tNewGet().\n\t\t\tPath(\"/markdown\"),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"%s\\n%s\", err, respBody)\n\t}\n\tfmt.Println(respWrong.Message)\n\tfmt.Println(respWrong.DocumentationUrl)\n\tfmt.Println(string(respBody))\n\t// Output:\n\t// Not Found\n\t// https://docs.github.com/rest\n\t// {\"message\":\"Not Found\",\"documentation_url\":\"https://docs.github.com/rest\"}\n}\n\nfunc ExampleXClient_Do_upload() {\n\ttmpTestdata := filepath.Join(os.TempDir(), \"testdata.json\")\n\tif err := os.WriteFile(tmpTestdata, []byte(`{\"x\",\"go\"}`), 0644); err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tdefer os.Remove(tmpTestdata)\n\n\ttype Response struct {\n\t\tFiles struct {\n\t\t\tTestfile string `json:\"testfile\"`\n\t\t} `json:\"files\"`\n\t\tForm struct {\n\t\t\tHello string `json:\"hello\"`\n\t\t} `json:\"form\"`\n\t}\n\n\tcli := NewClient().BaseURL(\"https://httpbin.org\")\n\n\tvar resp Response\n\t_, respBody, err := cli.DoOnceWithBodyCodec(BodyCodecMultipart, \u0026resp, nil,\n\t\tNewPost().\n\t\t\tPath(\"/post\").\n\t\t\tBody(\n\t\t\t\tNewMultipartWriter().\n\t\t\t\t\tWriteWithFieldValue(\"hello\", \"world\").\n\t\t\t\t\tWriteWithFile(\"testfile\", tmpTestdata),\n\t\t\t),\n\t)\n\tif err != nil {\n\t\tlog.Fatalf(\"%s\\n%s\", err, respBody)\n\t}\n\n\tfmt.Println(resp.Form.Hello)\n\tfmt.Println(resp.Files.Testfile)\n\t// Output:\n\t// world\n\t// {\"x\",\"go\"}\n}\n\nfunc ExampleXClient_Do_download() {\n\tcli := NewClient()\n\n\t_, resp, cancel, err := cli.DoWithRaw(\n\t\tNewGet().\n\t\t\tPath(\"https://raw.githubusercontent.com/electricbubble/xhttpclient/main/LICENSE\"),\n\t)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer cancel()\n\n\tvar buf bytes.Buffer\n\tif _, err = io.Copy(\u0026buf, resp.Body); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlicense, _, _ := strings.Cut(buf.String(), \"\\n\")\n\tfmt.Println(license)\n\t// Output:\n\t// MIT License\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectricbubble%2Fxhttpclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felectricbubble%2Fxhttpclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectricbubble%2Fxhttpclient/lists"}