{"id":13394022,"url":"https://github.com/parnurzeal/gorequest","last_synced_at":"2025-05-12T05:13:03.997Z","repository":{"id":14266516,"uuid":"16974335","full_name":"parnurzeal/gorequest","owner":"parnurzeal","description":"GoRequest -- Simplified HTTP client ( inspired by nodejs SuperAgent )","archived":false,"fork":false,"pushed_at":"2025-03-29T13:18:12.000Z","size":641,"stargazers_count":3484,"open_issues_count":117,"forks_count":417,"subscribers_count":59,"default_branch":"develop","last_synced_at":"2025-05-12T02:37:51.049Z","etag":null,"topics":["go","golang","gorequest","json","library"],"latest_commit_sha":null,"homepage":"http://parnurzeal.github.io/gorequest/","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/parnurzeal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","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":"2014-02-19T05:06:37.000Z","updated_at":"2025-05-12T01:53:25.000Z","dependencies_parsed_at":"2025-04-08T20:01:35.776Z","dependency_job_id":"da60516c-35bc-4f10-8580-d5c080651ab4","html_url":"https://github.com/parnurzeal/gorequest","commit_stats":{"total_commits":290,"total_committers":48,"mean_commits":6.041666666666667,"dds":0.4724137931034482,"last_synced_commit":"3a0cb377f5710017dec64a04559707693434c708"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parnurzeal%2Fgorequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parnurzeal%2Fgorequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parnurzeal%2Fgorequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parnurzeal%2Fgorequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parnurzeal","download_url":"https://codeload.github.com/parnurzeal/gorequest/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253672614,"owners_count":21945477,"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":["go","golang","gorequest","json","library"],"created_at":"2024-07-30T17:01:06.072Z","updated_at":"2025-05-12T05:13:03.977Z","avatar_url":"https://github.com/parnurzeal.png","language":"Go","funding_links":[],"categories":["Misc","HTTP","Links Úteis","Go","Utilities","实用工具","工具库","Repositories","Golang"],"sub_categories":["Em Português","Advanced Console UIs","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Http Client"],"readme":"GoRequest\n=========\n\nGoRequest -- Simplified HTTP client ( inspired by famous SuperAgent lib in Node.js )\n\n![GopherGoRequest](https://raw.githubusercontent.com/parnurzeal/gorequest/gh-pages/images/Gopher_GoRequest_400x300.jpg)\n\n#### \"Shooting Requests like a Machine Gun\" - Gopher\n\nSending request has never been as fun nor easier than this. It comes with lots of features:\n\n* Get/Post/Put/Head/Delete/Patch/Options\n* Set - simple header setting\n* JSON - made it simple with JSON string as a parameter\n* Multipart-Support - send data and files as multipart request\n* Proxy - sending request via proxy\n* Timeout - setting timeout for a request\n* TLSClientConfig - taking control over tls where at least you can disable security check for https\n* RedirectPolicy\n* Cookie - setting cookies for your request\n* CookieJar - automatic in-memory cookiejar\n* BasicAuth - setting basic authentication header\n* more to come..\n\n## Installation\n\n```bash\n$ go get github.com/parnurzeal/gorequest\n```\n\n## Documentation\nSee [Go Doc](http://godoc.org/github.com/parnurzeal/gorequest) or [Go Walker](http://gowalker.org/github.com/parnurzeal/gorequest) for usage and details.\n\n## Status\n\n[![Drone Build Status](https://drone.io/github.com/jmcvetta/restclient/status.png)](https://drone.io/github.com/parnurzeal/gorequest/latest)\n[![Travis Build Status](https://travis-ci.org/parnurzeal/gorequest.svg?branch=master)](https://travis-ci.org/parnurzeal/gorequest)\n\n## Why should you use GoRequest?\n\nGoRequest makes thing much more simple for you, making http client more awesome and fun like SuperAgent + golang style usage.\n\nThis is what you normally do for a simple GET without GoRequest:\n\n```go\nresp, err := http.Get(\"http://example.com/\")\n```\n\nWith GoRequest:\n\n```go\nrequest := gorequest.New()\nresp, body, errs := request.Get(\"http://example.com/\").End()\n```\n\nOr below if you don't want to reuse it for other requests.\n\n```go\nresp, body, errs := gorequest.New().Get(\"http://example.com/\").End()\n```\n\nHow about getting control over HTTP client headers, redirect policy, and etc. Things can quickly get more complicated in golang. You need to create a Client, set headers in a different command, ... just to do only one __GET__\n\n```go\nclient := \u0026http.Client{\n  CheckRedirect: redirectPolicyFunc,\n}\n\nreq, err := http.NewRequest(\"GET\", \"http://example.com\", nil)\n\nreq.Header.Add(\"If-None-Match\", `W/\"wyzzy\"`)\nresp, err := client.Do(req)\n```\n\nWhy make things ugly while you can just do it as follows:\n\n```go\nrequest := gorequest.New()\nresp, body, errs := request.Get(\"http://example.com\").\n  RedirectPolicy(redirectPolicyFunc).\n  Set(\"If-None-Match\", `W/\"wyzzy\"`).\n  End()\n```\n\n__DELETE__, __HEAD__, __POST__, __PUT__, __PATCH__ are now supported and can be used in the same way as __GET__:\n\n```go\nrequest := gorequest.New()\nresp, body, errs := request.Post(\"http://example.com\").End()\n// PUT -\u003e request.Put(\"http://example.com\").End()\n// DELETE -\u003e request.Delete(\"http://example.com\").End()\n// HEAD -\u003e request.Head(\"http://example.com\").End()\n// ANYTHING -\u003e request.CustomMethod(\"TRACE\", \"http://example.com\").End()\n```\n\n### JSON\n\nFor a __JSON POST__ with standard libraries, you might need to marshal map data structure to json format, set headers to 'application/json' (and other headers if you need to) and declare http.Client. So, your code becomes longer and harder to maintain:\n\n```go\nm := map[string]interface{}{\n  \"name\": \"backy\",\n  \"species\": \"dog\",\n}\nmJson, _ := json.Marshal(m)\ncontentReader := bytes.NewReader(mJson)\nreq, _ := http.NewRequest(\"POST\", \"http://example.com\", contentReader)\nreq.Header.Set(\"Content-Type\", \"application/json\")\nreq.Header.Set(\"Notes\",\"GoRequest is coming!\")\nclient := \u0026http.Client{}\nresp, _ := client.Do(req)\n```\n\nCompared to our GoRequest version, JSON is for sure a default. So, it turns out to be just one simple line!:\n\n```go\nrequest := gorequest.New()\nresp, body, errs := request.Post(\"http://example.com\").\n  Set(\"Notes\",\"gorequst is coming!\").\n  Send(`{\"name\":\"backy\", \"species\":\"dog\"}`).\n  End()\n```\n\nMoreover, it also supports struct type. So, you can have a fun __Mix \u0026 Match__ sending the different data types for your request:\n\n```go\ntype BrowserVersionSupport struct {\n  Chrome string\n  Firefox string\n}\nver := BrowserVersionSupport{ Chrome: \"37.0.2041.6\", Firefox: \"30.0\" }\nrequest := gorequest.New()\nresp, body, errs := request.Post(\"http://version.com/update\").\n  Send(ver).\n  Send(`{\"Safari\":\"5.1.10\"}`).\n  End()\n```\n\nNot only for Send() but Query() is also supported. Just give it a try! :)\n\n## Callback\n\nMoreover, GoRequest also supports callback function. This gives you much more flexibility on using it. You can use it any way to match your own style!\nLet's see a bit of callback example:\n\n```go\nfunc printStatus(resp gorequest.Response, body string, errs []error){\n  fmt.Println(resp.Status)\n}\ngorequest.New().Get(\"http://example.com\").End(printStatus)\n```\n\n## Multipart/Form-Data\n\nYou can specify the content-type of the request to type `multipart` to send all data as `multipart/form-data`. This feature also allows you to send (multiple) files! Check the examples below!\n\n```go\ngorequest.New().Post(\"http://example.com/\").\n  Type(\"multipart\").\n  Send(`{\"query1\":\"test\"}`).\n  End()\n```\n\nThe `SendFile` function accepts `strings` as path to a file, `[]byte` slice or even a `os.File`! You can also combine them to send multiple files with either custom name and/or custom fieldname:\n\n```go\n          f, _ := filepath.Abs(\"./file2.txt\")\nbytesOfFile, _ := ioutil.ReadFile(f)\n\ngorequest.New().Post(\"http://example.com/\").\n  Type(\"multipart\").\n  SendFile(\"./file1.txt\").\n  SendFile(bytesOfFile, \"file2.txt\", \"my_file_fieldname\").\n  End()\n```\n\nCheck the docs for `SendFile` to get more information about the types of arguments.\n\n## Headers\n\nWhen setting one header to the request, the `Set` method can be used:\n\n```go\ngorequest.New().\n      Post(\"/gamelist\").\n      Set(\"Accept\", \"application/json\").\n      End()\n```\n\nThis will clear all headers currently attached to a request and add the specified header.\n\nIf there are multiple headers that must be appended to the request before sending, use `AppendHeader`. These can be chained together to add additional headers to the request:\n\n```go\ngorequest.New().\n      Post(\"/gamelist\").\n      AppendHeader(\"Accept\", \"application/json\").\n      AppendHeader(\"Accept\", \"text/plain\").\n      End()\n```\n\nSee the docs for the `Set` and `AppendHeader` methods for information about parameter and return types.\n\n## Proxy\n\nIn the case when you are behind proxy, GoRequest can handle it easily with Proxy func:\n\n```go\nrequest := gorequest.New().Proxy(\"http://proxy:999\")\nresp, body, errs := request.Get(\"http://example-proxy.com\").End()\n// To reuse same client with no_proxy, use empty string:\nresp, body, errs = request.Proxy(\"\").Get(\"http://example-no-proxy.com\").End()\n```\n\n## Basic Authentication\n\nTo add a basic authentication header:\n\n```go\nrequest := gorequest.New().SetBasicAuth(\"username\", \"password\")\nresp, body, errs := request.Get(\"http://example-proxy.com\").End()\n```\n\n## Timeout\n\nTimeout can be set in any time duration using time package:\n\n```go\nrequest := gorequest.New().Timeout(2*time.Millisecond)\nresp, body, errs:= request.Get(\"http://example.com\").End()\n```\n\nTimeout func defines both dial + read/write timeout to the specified time parameter.\n\n## EndBytes\n\nThanks to @jaytaylor, we now have EndBytes to use when you want the body as bytes.\n\nThe callbacks work the same way as with `End`, except that a byte array is used instead of a string.\n\n```go\nresp, bodyBytes, errs := gorequest.New().Get(\"http://example.com/\").EndBytes()\n```\n\n## EndStruct\n\nWe now have EndStruct to use when you want the body as struct.\n\nThe callbacks work the same way as with `End`, except that a struct is used instead of a string.\n\nSupposing the URL **http://example.com/** returns the body `{\"hey\":\"you\"}`\n\n```go\nheyYou struct {\n  Hey string `json:\"hey\"`\n}\n\nvar heyYou heyYou\n\nresp, _, errs := gorequest.New().Get(\"http://example.com/\").EndStruct(\u0026heyYou)\n```\n\n## Retry\n\nSupposing you need retry 3 times, with 5 seconds between each attempt when gets a BadRequest or a InternalServerError\n\n```go\nrequest := gorequest.New()\nresp, body, errs := request.Get(\"http://example.com/\").\n                    Retry(3, 5 * time.Second, http.StatusBadRequest, http.StatusInternalServerError).\n                    End()\n```\n\n## Handling Redirects\n\nRedirects can be handled with RedirectPolicy which behaves similarly to\nnet/http Client's [CheckRedirect\nfunction](https://golang.org/pkg/net/http#Client). Simply specify a function\nwhich takes the Request about to be made and a slice of previous Requests in\norder of oldest first. When this function returns an error, the Request is not\nmade.\n\nFor example to redirect only to https endpoints:\n\n```go\nrequest := gorequest.New()\nresp, body, errs := request.Get(\"http://example.com/\").\n                    RedirectPolicy(func(req Request, via []*Request) error {\n                      if req.URL.Scheme != \"https\" {\n                        return http.ErrUseLastResponse\n                      }\n                    }).\n                    End()\n```\n\n\n## Clone\n\nYou can reuse settings of a Request by cloning it _before_ making any requests. This can be useful if you wish to re-use the SuperAgent across multiple requests without worrying about concurrency or having too many Transports being created.\n\nClones will copy the same settings (headers, query, etc..), but will only shallow copy any \"Data\" given to it. They will also share the same Transport and http.Client.\n\n```go\nbaseRequest := gorequest.New()\n// apply anything you want to these settings. Eg:\nbaseRequest.Timeout(10 * time.Millisecond).\n  BasicAuth(\"user\", \"password\")\n\n// then reuse the base request elsewhere, cloning before modifying or using it.\nresp, body, errs := baseRequest.Clone().Get(\"http://exmaple.com/\").End()\n```\n\n## Debug\n\nFor debugging, GoRequest leverages `httputil` to dump details of every request/response. (Thanks to @dafang)\n\nYou can just use `SetDebug` or environment variable `GOREQUEST_DEBUG=0|1` to enable/disable debug mode and `SetLogger` to set your own choice of logger.\n\nThanks to @QuentinPerez, we can see even how gorequest is compared to CURL by using `SetCurlCommand`.\n\n## Noted\nAs the underlying gorequest is based on http.Client in most use cases, gorequest.New() should be called once and reuse gorequest as much as possible.\n\n## Contributing to GoRequest:\n\nIf you find any improvement or issue you want to fix, feel free to send me a pull request with testing.\n\nThanks to all contributors thus far:\n\n\n|   Contributors                        |\n|---------------------------------------|\n| https://github.com/alaingilbert       |\n| https://github.com/austinov           |\n| https://github.com/coderhaoxin        |\n| https://github.com/codegoalie         |\n| https://github.com/dafang             |\n| https://github.com/davyzhang          |\n| https://github.com/dickeyxxx          |\n| https://github.com/figlief            |\n| https://github.com/fraenky8           |\n| https://github.com/franciscocpg       |\n| https://github.com/heytitle           |\n| https://github.com/hownowstephen      |\n| https://github.com/kemadz             |\n| https://github.com/killix             |\n| https://github.com/jaytaylor          |\n| https://github.com/na-ga              |\n| https://github.com/piotrmiskiewicz    |\n| https://github.com/pencil001          |\n| https://github.com/pkopac             |\n| https://github.com/quangbuule         |\n| https://github.com/QuentinPerez       |\n| https://github.com/smallnest          |\n| https://github.com/WaveCutz           |\n| https://github.com/xild               |\n| https://github.com/yangmls            |\n| https://github.com/6david9            |\n\n\nAlso, co-maintainer is needed here. If anyone is interested, please email me (parnurzeal at gmail.com)\n\n## Credits\n\n* Renee French - the creator of Gopher mascot\n* [Wisi Mongkhonsrisawat](https://www.facebook.com/puairw) for providing an awesome GoRequest's Gopher image :)\n\n## License\n\nGoRequest is MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparnurzeal%2Fgorequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparnurzeal%2Fgorequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparnurzeal%2Fgorequest/lists"}