{"id":13413658,"url":"https://github.com/ddo/rq","last_synced_at":"2025-12-30T01:43:54.049Z","repository":{"id":57483289,"uuid":"115413677","full_name":"ddo/rq","owner":"ddo","description":"A nicer interface for golang stdlib HTTP client","archived":false,"fork":false,"pushed_at":"2019-08-28T17:45:31.000Z","size":44,"stargazers_count":51,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-31T20:52:37.572Z","etag":null,"topics":["client","golang","http","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ddo.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-12-26T10:48:27.000Z","updated_at":"2023-12-16T01:22:43.000Z","dependencies_parsed_at":"2022-08-27T23:21:53.843Z","dependency_job_id":null,"html_url":"https://github.com/ddo/rq","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddo%2Frq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddo%2Frq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddo%2Frq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddo%2Frq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddo","download_url":"https://codeload.github.com/ddo/rq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221498771,"owners_count":16833059,"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":["client","golang","http","http-client"],"created_at":"2024-07-30T20:01:45.649Z","updated_at":"2025-12-30T01:43:54.012Z","avatar_url":"https://github.com/ddo.png","language":"Go","readme":"# rq [![Build Status][githubaction-img]][githubaction-url] [![Go Report][goreport-img]][goreport-url] [![codecov][codecov-img]][codecov-url]\n\nA nicer interface for golang stdlib HTTP client\n\n## Documents\n\n-   rq: [here][godoc-url]\n-   client: [here][godoc-client-url]\n-   jar: [here][godoc-jar-url]\n\n[godoc-img]: https://img.shields.io/badge/godoc-Reference-brightgreen.svg\n[godoc-url]: https://godoc.org/github.com/ddo/rq\n[godoc-client-url]: https://godoc.org/github.com/ddo/rq/client\n[godoc-jar-url]: https://godoc.org/github.com/ddo/rq/client/jar\n[githubaction-img]: https://github.com/ddo/rq/workflows/Go/badge.svg\n[githubaction-url]: https://github.com/ddo/rq/actions\n[goreport-img]: https://goreportcard.com/badge/github.com/ddo/rq\n[goreport-url]: https://goreportcard.com/report/github.com/ddo/rq\n[codecov-img]: https://codecov.io/gh/ddo/rq/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/ddo/rq\n\n## Why?\n\nBecause golang HTTP client is a pain in the a...\n\n## Features\n\n-   Compatible with golang `http` stdlib: `http.Request`, `http.Response` and `http.Cookie`\n-   Step by step to build your **request**\n-   Better HTTP **client**\n-   Better **cookie jar**\n-   **Import/export** allow we save/transfer requests in JSON\n-   **Default setting**: example default `User-Agent` or `Accept-Language`\n\n## Installation\n\n```sh\ngo get -u github.com/ddo/rq\n```\n\n## Getting started\n\n### Simple\n\n```go\nimport \"net/http\"\nimport \"github.com/ddo/rq\"\n\nr := rq.Get(\"https://httpbin.org/get\")\n\n// query https://httpbin.org/get?q=1\u0026q=2\u0026q=3\u0026_=123456\nr.Qs(\"q\", \"1\", \"2\")\nr.Qs(\"q\", \"3\")\nr.Qs(\"_\", \"123456\")\n\n// send with golang default HTTP client\nres, err := http.DefaultClient.Do(r.ParseRequest())\ndefer res.Body.Close()\n```\n\n### Custom client\n\nIn case you did not know that golang default `http.Client` has **no timeout**.\nuse **rq/client** which has `180s` timeout by default\n\n```go\nimport \"github.com/ddo/rq\"\nimport \"github.com/ddo/rq/client\"\n\nr := rq.Post(\"https://httpbin.org/post\")\n\n// query\nr.Qs(\"_\", \"123456\")\n\n// Form\nr.Send(\"data\", \"data value\")\nr.Send(\"extra\", \"extra value\")\n\n// use default rq client\n// true to tell #Send to read all the response boby when return\ndata, res, err := client.Send(r, true)\n// no need to close res.Body\n// read = false -\u003e you need to call res.Body when done reading\n```\n\n### Headers\n\n```go\nr := rq.Post(\"https://httpbin.org/post\")\n\nr.Set(\"Content-Type\", \"application/json\")\nr.Set(\"User-Agent\", \"ddo/rq\")\n```\n\n### Raw body\n\n```go\nr := rq.Post(\"https://httpbin.org/post\")\n\nr.SendRaw(strings.NewReader(\"raw data binary or json\"))\n```\n\n## Client [![Doc][godoc-img]][godoc-client-url]\n\n### Default\n\n```go\n// by default timeout = 3min\n// no cookie jar\n// and stops after 10 consecutive requests (10 redirects)\ncustomClient := client.New(nil)\n```\n\n### Custom Options\n\n```go\nimport \"github.com/ddo/rq/client/jar\"\n\ncookieJar := jar.New()\n\n// custom timeout = 10s and cookie jar\ncustomClient := client.New(\u0026Option{\n    Timeout: time.Second * 10,\n    jar: cookieJar,\n})\n```\n\n### Default settings\n\n```go\n// set default User-Agent\ndefaultRq := rq.Get(\"\")\ndefaultRq.Set(\"User-Agent\", \"github.com/ddo/rq\")\n\ncustomClient := client.New(\u0026Option{\n    DefaultRq: defaultRq,\n})\n\n// from now all the requests called via this customClient\n// gonna have the User-Agent header = \"github.com/ddo/rq\"\n// if User-Agent header in request is not set\n```\n\n## Redirect\n\n-   Default `client` stops after 10 consecutive requests\n-   Or you can use `client.NoRedirect` to disable redirect\n\n```go\nclient.New(\u0026Option{\n    CheckRedirect: client.NoCheckRedirect,\n})\n```\n\n## Cookies [![Doc][godoc-img]][godoc-jar-url]\n\n```go\nimport \"github.com/ddo/rq/client/jar\"\n\ncookieJar := jar.New()\n\ncustomClient := client.New(\u0026client.Option{\n    Jar: cookieJar,\n})\n\n// get all cookies by hostname\ncookies, err := cookieJar.Get(\"httpbin.org\")\n\n// get a cookie by hostname and name\ncookie, err := cookieJar.GetByName(\"httpbin.org\", \"cookiename\").\n\n// set cookies\nerr := cookieJar.Set(\"httpbin.org\", cookies)\n\n// set a cookie\nerr := cookieJar.SetOne(\"httpbin.org\", cookie)\n\n// clear the cookie jar\nerr := cookieJar.Clear(\"httpbin.org\")\n\n// delete a cookie by it's name\nerr := cookieJar.Delete(\"httpbin.org\", \"cookiename\")\n```\n\n## Debug\n\nSet env `DLOG=*` to enable logger to see request activities\n\n## TODO\n\nList here [#1](https://github.com/ddo/rq/issues/1)","funding_links":[],"categories":["Networking","网络","Utilities","网络相关库","HTTP Clients","实用工具","工具库"],"sub_categories":["HTTP Clients","HTTP客户端","Http Client","Advanced Console UIs","交流"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddo%2Frq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddo%2Frq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddo%2Frq/lists"}