{"id":24440550,"url":"https://github.com/lib4u/grequest","last_synced_at":"2025-08-29T03:45:46.462Z","repository":{"id":271249664,"uuid":"912341061","full_name":"lib4u/grequest","owner":"lib4u","description":"Simple golang library for http requests","archived":false,"fork":false,"pushed_at":"2025-01-31T17:20:54.000Z","size":84,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-30T16:22:59.446Z","etag":null,"topics":["golang","golang-module","golang-package","http-client","http-requests"],"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/lib4u.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":"2025-01-05T09:56:34.000Z","updated_at":"2025-03-05T22:04:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"67ce1c97-1e40-4b01-8fed-d1bbebf9fb9d","html_url":"https://github.com/lib4u/grequest","commit_stats":null,"previous_names":["lib4u/grequest"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lib4u%2Fgrequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lib4u%2Fgrequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lib4u%2Fgrequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lib4u%2Fgrequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lib4u","download_url":"https://codeload.github.com/lib4u/grequest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251711687,"owners_count":21631293,"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-module","golang-package","http-client","http-requests"],"created_at":"2025-01-20T20:55:35.245Z","updated_at":"2025-04-30T13:13:22.678Z","avatar_url":"https://github.com/lib4u.png","language":"Go","readme":"![logo](https://github.com/user-attachments/assets/3bef5ed3-a40b-4634-9de4-a2dd43d57f3d)\n\n\n**A simple and lightweight HTTP client for Go, inspired by Requests (Python) and Guzzle (PHP).**\n\nGrequests provides a declarative, chainable API to streamline HTTP requests in Go, supporting JSON manipulation, form submissions, cookies, file handling, authentication, and proxy configuration—all while remaining lightweight and dependency-free.\n\n---\n\n## **Features**\n\n- **Lightweight \u0026 Efficient**: No third-party dependencies, built directly on `net/http`.\n- **Flexible Request Handling**: Supports GET, POST, PUT, DELETE, and other HTTP methods.\n- **JSON Parsing**: Convert responses into Go structs or string maps.\n- **Header \u0026 Cookie Management**: Easily set, retrieve, and persist headers and cookies.\n- **File Handling**: Upload and download files seamlessly.\n- **Authentication**: Supports Basic, Bearer, and custom token authentication.\n- **Proxy Support**: Configure custom proxy servers for HTTP requests.\n\n---\n\n## **Installation**\n\nInstall Grequests using Go modules:\n\n```sh\ngo get github.com/lib4u/grequest\n```\n\nOr build from source:\n\n```sh\ngit clone https://github.com/lib4u/grequest.git\ncd grequest\ngo build -o grequest ./\n./grequest --version\n```\n\n---\n\n## **Usage**\n\n### **Basic GET Request**\n\n```go\nreq := app.Get(\"https://jsonplaceholder.typicode.com/todos/1\").Do()\nfmt.Println(req.Body().GetStrings())\n```\n\n### **Parsing JSON Response**\n\n```go\ntype Todo struct {\n    UserID    int    `json:\"userId\"`\n    ID        int    `json:\"id\"`\n    Title     string `json:\"title\"`\n    Completed bool   `json:\"completed\"`\n}\n\nvar todo Todo\nreq := app.Get(\"https://jsonplaceholder.typicode.com/todos/1\").Do()\nerr := req.Body().GetWithJsonStruct(\u0026todo)\nif err != nil {\n    fmt.Println(\"Error decoding JSON\")\n}\nfmt.Println(todo.Title)\n```\n\n### **POST Request with JSON Payload**\n\n```go\ndata := LoginRequest{\n    Username: \"example\",\n    Password: \"12345\",\n}\nreq := app.Post(\"https://example.site/login\").Body().SetJson(data).Do()\nfmt.Println(req.Status().GetCode())\n```\n\n### **Downloading a File**\n\n```go\napp.Get(\"https://example.com/image.png\").Do().Body().SaveFile()\n```\n\n### **Multipart Form Submission**\n\n```go\nreq := app.Post(\"https://example.site/form/\")\nreq.Header().Set(\"Client\", \"number_1\")\nform := req.FormData().WithMultipart()\nform.AddField(\"first_name\", \"John\")\nform.AddFile(\"photo\", \"my_photo.png\")\nform.Push()\nreq.Do()\n```\n\n### **Set count of maximum redirects and retry request if get 404 or 500 HTTP code**\n\n```go\nreq := app.Get(\"https://jsonplaceholder.typicode.com/todos/1\").MaxRedirect(1).RetryIf(404, 500).Do()\nfmt.Println(req.Body().GetStrings())\n```\n\n### **Set your context**\n\n```go\nctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)\ndefer cancel()\nreq := app.Get(\"https://jsonplaceholder.typicode.com/todos/1\").DoWithContext(ctx)\nfmt.Println(req.Body().GetStrings())\n```\n\n### **Authenticated Requests**\n\n```go\n// Basic Authentication\napp.Post(\"https://example.site/secret\").Auth().SetBasic(\"user\", \"password\").Do()\n\n// Bearer Token Authentication\napp.Post(\"https://example.site/secret\").Auth().SetBearer(\"myToken\").Do()\n\n// Custom Token Authentication\napp.Post(\"https://example.site/secret\").Auth().SetToken(\"Token\", \"myToken\").Do()\n\n// Custom Header Authentication\napp.Post(\"https://example.site/secret\").Auth().SetHeader(\"JSESSIONID\", \"12345\").Do()\n```\n\n### **Cookie Handling**\n\n```go\n//Save cookie to file \n//By default this saved in  cookies/example.site/cookies.json\nreq := app.Post(\"https://example.site/cookies\")\nreq.Cookie().Save()\n\n// Load saved cookies form cookies/example.site/cookies.json\nreqWithCookie := app.Post(\"https://example.site/cookies\")\nreqWithCookie.Cookie().Load()\nreqWithCookie.Do()\n\n// Clear cookies\nreqWithCookie.Cookie().Clear()\n```\n---\n\n## **Contributing**\n\n1. Fork the repository and clone it locally.\n2. Create a new branch (`git checkout -b feature/branch-name`).\n3. Make your changes and commit (`git commit -m \"Description of changes\"`).\n4. Push your changes and create a pull request.\n\n---\n\n## **License**\n\nGrequests is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\nFor more details, visit the [GitHub repository](https://github.com/lib4u/grequest).\n\n---\n","funding_links":[],"categories":["Networking","网络"],"sub_categories":["HTTP Clients","HTTP客户端"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flib4u%2Fgrequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flib4u%2Fgrequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flib4u%2Fgrequest/lists"}