{"id":13413651,"url":"https://github.com/levigross/grequests","last_synced_at":"2025-05-14T10:13:57.704Z","repository":{"id":33621098,"uuid":"37273343","full_name":"levigross/grequests","owner":"levigross","description":"A Go \"clone\" of the great and famous Requests library","archived":false,"fork":false,"pushed_at":"2024-05-08T09:13:29.000Z","size":188,"stargazers_count":2145,"open_issues_count":28,"forks_count":139,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-03T17:08:38.218Z","etag":null,"topics":["golang","golang-package","grequests","http-client","requests"],"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/levigross.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":"2015-06-11T16:41:48.000Z","updated_at":"2025-03-31T07:09:07.000Z","dependencies_parsed_at":"2023-01-15T01:41:25.891Z","dependency_job_id":"41115d34-1873-4a1e-9e78-421ef5490e08","html_url":"https://github.com/levigross/grequests","commit_stats":{"total_commits":110,"total_committers":13,"mean_commits":8.461538461538462,"dds":"0.19090909090909092","last_synced_commit":"9c307ef1f48d69f109971226c4e8ff9ca850a2d6"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levigross%2Fgrequests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levigross%2Fgrequests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levigross%2Fgrequests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levigross%2Fgrequests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/levigross","download_url":"https://codeload.github.com/levigross/grequests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248338182,"owners_count":21087175,"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-package","grequests","http-client","requests"],"created_at":"2024-07-30T20:01:45.451Z","updated_at":"2025-04-11T03:37:40.045Z","avatar_url":"https://github.com/levigross.png","language":"Go","readme":"# GRequests\nA Go \"clone\" of the great and famous Requests library\n\n[![Join the chat at https://gitter.im/levigross/grequests](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/levigross/grequests?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nLicense\n======\n\nGRequests is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text\n\nFeatures\n========\n\n- Responses can be serialized into JSON and XML\n- Easy file uploads\n- Easy file downloads\n- Support for the following HTTP verbs `GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS`\n\nInstall\n=======\n`go get -u github.com/levigross/grequests`\n\nUsage\n======\n`import \"github.com/levigross/grequests\"`\n\nBasic Examples\n=========\nBasic GET request:\n\n```go\nresp, err := grequests.Get(\"http://httpbin.org/get\", nil)\n// You can modify the request by passing an optional RequestOptions struct\n\nif err != nil {\n\tlog.Fatalln(\"Unable to make request: \", err)\n}\n\nfmt.Println(resp.String())\n// {\n//   \"args\": {},\n//   \"headers\": {\n//     \"Accept\": \"*/*\",\n//     \"Host\": \"httpbin.org\",\n```\n\nIf an error occurs all of the other properties and methods of a `Response` will be `nil`\n\nQuirks\n=======\n## Request Quirks\n\nWhen passing parameters to be added to a URL, if the URL has existing parameters that *_contradict_* with what has been passed within `Params` – `Params` will be the \"source of authority\" and overwrite the contradicting URL parameter.\n\nLets see how it works...\n\n```go\nro := \u0026RequestOptions{\n\tParams: map[string]string{\"Hello\": \"Goodbye\"},\n}\nGet(\"http://httpbin.org/get?Hello=World\", ro)\n// The URL is now http://httpbin.org/get?Hello=Goodbye\n```\n\n## Response Quirks\n\nOrder matters! This is because `grequests.Response` is implemented as an `io.ReadCloser` which proxies the *http.Response.Body* `io.ReadCloser` interface. It also includes an internal buffer for use in `Response.String()` and `Response.Bytes()`.\n\nHere are a list of methods that consume the *http.Response.Body* `io.ReadCloser` interface.\n\n- Response.JSON\n- Response.XML\n- Response.DownloadToFile\n- Response.Close\n- Response.Read\n\nThe following methods make use of an internal byte buffer\n\n- Response.String\n- Response.Bytes\n\nIn the code below, once the file is downloaded – the `Response` struct no longer has access to the request bytes\n\n```go\nresponse := Get(\"http://some-wonderful-file.txt\", nil)\n\nif err := response.DownloadToFile(\"randomFile\"); err != nil {\n\tlog.Println(\"Unable to download file: \", err)\n}\n\n// At this point the .String and .Bytes method will return empty responses\n\nresponse.Bytes() == nil // true\nresponse.String() == \"\" // true\n\n```\n\nBut if we were to call `response.Bytes()` or `response.String()` first, every operation will succeed until the internal buffer is cleared:\n\n```go\nresponse := Get(\"http://some-wonderful-file.txt\", nil)\n\n// This call to .Bytes caches the request bytes in an internal byte buffer – which can be used again and again until it is cleared\nresponse.Bytes() == `file-bytes`\nresponse.String() == \"file-string\"\n\n// This will work because it will use the internal byte buffer\nif err := resp.DownloadToFile(\"randomFile\"); err != nil {\n\tlog.Println(\"Unable to download file: \", err)\n}\n\n// Now if we clear the internal buffer....\nresponse.ClearInternalBuffer()\n\n// At this point the .String and .Bytes method will return empty responses\n\nresponse.Bytes() == nil // true\nresponse.String() == \"\" // true\n```\n","funding_links":[],"categories":["Networking","Misc","网络","Go","Utilities","HTTP客户端库","实用工具","网络相关库","HTTP Clients","工具库","實用工具"],"sub_categories":["HTTP Clients","HTTP客户端","Advanced Console UIs","交互工具","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Http Client","交流","高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevigross%2Fgrequests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevigross%2Fgrequests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevigross%2Fgrequests/lists"}