{"id":24107806,"url":"https://github.com/alessiosavi/requests","last_synced_at":"2025-09-10T15:41:50.903Z","repository":{"id":47180828,"uuid":"209804769","full_name":"alessiosavi/Requests","owner":"alessiosavi","description":"A Go library for reduce the headache when making HTTP requests (20k/s req) and send parallel request","archived":false,"fork":false,"pushed_at":"2023-03-07T00:59:54.000Z","size":7691,"stargazers_count":8,"open_issues_count":5,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T01:40:35.267Z","etag":null,"topics":["go","golang","http-client","http-parallel-request","http-request","parallel","parallel-requests","post"],"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/alessiosavi.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}},"created_at":"2019-09-20T14:04:35.000Z","updated_at":"2023-04-23T01:11:48.000Z","dependencies_parsed_at":"2022-08-02T23:45:37.840Z","dependency_job_id":null,"html_url":"https://github.com/alessiosavi/Requests","commit_stats":{"total_commits":61,"total_committers":4,"mean_commits":15.25,"dds":0.2295081967213115,"last_synced_commit":"5a30cfbf499367b0c94135d1e581ea77538cfba1"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiosavi%2FRequests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiosavi%2FRequests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiosavi%2FRequests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiosavi%2FRequests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alessiosavi","download_url":"https://codeload.github.com/alessiosavi/Requests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253796889,"owners_count":21965803,"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","http-client","http-parallel-request","http-request","parallel","parallel-requests","post"],"created_at":"2025-01-10T22:53:01.603Z","updated_at":"2025-05-12T18:26:30.926Z","avatar_url":"https://github.com/alessiosavi.png","language":"Go","readme":"# Requests\r\n\r\nA golang library for avoid headache during HTTP request\r\n\r\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/50714e195c544ab1b5e4e40d94a43998)](https://www.codacy.com/manual/alessiosavi/Requests?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=alessiosavi/Requests\u0026amp;utm_campaign=Badge_Grade)\r\n[![Go Report Card](https://goreportcard.com/badge/github.com/alessiosavi/Requests)](https://goreportcard.com/report/github.com/alessiosavi/Requests) [![GoDoc](https://godoc.org/github.com/alessiosavi/Requests?status.svg)](https://godoc.org/github.com/alessiosavi/Requests) [![License](https://img.shields.io/github/license/alessiosavi/Requests)](https://img.shields.io/github/license/alessiosavi/Requests) [![Version](https://img.shields.io/github/v/tag/alessiosavi/Requests)](https://img.shields.io/github/v/tag/alessiosavi/Requests) [![Code size](https://img.shields.io/github/languages/code-size/alessiosavi/Requests)](https://img.shields.io/github/languages/code-size/alessiosavi/Requests) [![Repo size](https://img.shields.io/github/repo-size/alessiosavi/Requests)](https://img.shields.io/github/repo-size/alessiosavi/Requests) [![Issue open](https://img.shields.io/github/issues/alessiosavi/Requests)](https://img.shields.io/github/issues/alessiosavi/Requests)\r\n[![Issue closed](https://img.shields.io/github/issues-closed/alessiosavi/Requests)](https://img.shields.io/github/issues-closed/alessiosavi/Requests)\r\n\r\n## Example usage\r\n\r\n`Requests` can work in two different method:\r\n\r\n- Single request\r\n- Multiple request in parallel\r\n\r\n### Single Request\r\n\r\nIn order to make a `Request`, you need to initialize the client:\r\n\r\n```go\r\n// Initialize request\r\nvar req requests.Request\r\n```\r\n\r\nNow the request is ready to be populated with `headers` or `body-data` if necessary.\r\n\r\nYou can create a list of headers and explode the data into the delegated method. In alternative, you can pass a given number of headers to the method.  \r\n***NOTE***: The headers have to be a \"key:value\" list so the first argument will be the key of the header, the one after will be the value.\r\n\r\n```go\r\n//Set custom headers directly in the method\r\nreq.CreateHeaderList(\"Content-Type\", \"text/plain; charset=UTF-8\", \"Authorization\", \"Basic cG9zdG1hbjpwYXNzd29yZA==\")\r\n// Or create a list of headers and use them in the method\r\nvar headers []string\r\nheaders = append(headers, \"Content-Type\")\r\nheaders = append(headers, \"text/plain; charset=UTF-8\")\r\nheaders = append(headers, \"Authorization\")\r\nheaders = append(headers, \"Basic cG9zdG1hbjpwYXNzd29yZA==\")\r\nreq.CreateHeaderList(headers...)\r\n```\r\n\r\nNow you can send a request to the URL\r\n\r\n```go\r\n// Send the request and save to a properly structure\r\n// GET, without BODY data (only used in POST), and enabling SSL certificate validation (skipTLS: false)\r\nresponse := req.SendRequest(\"https://postman-echo.com/get?foo1=bar1\u0026foo2=bar2\", \"GET\", nil, false)\r\n\r\n// Debug the response\r\nfmt.Println(\"Headers: \", response.Headers)\r\nfmt.Println(\"Status code: \", response.StatusCode)\r\nfmt.Println(\"Time elapsed: \", response.Time)\r\nfmt.Println(\"Error: \", response.Error)\r\nfmt.Println(\"Body: \", string(response.Body))\r\n```\r\n\r\n### Multiple request in parallel\r\n\r\nIn order to use the parallel request, you have to create a list of request that have to be executed, than you can call the delegated method for send them in parallel, choosing how many requests have to be sent in parallel.\r\n\r\nIn first instance populate an array with the requests that you need to send:\r\n\r\n```go\r\n// This array will contains the list of request\r\nvar reqs []requests.Request\r\n\r\n// N is the number of request to run in parallel, in order to avoid \"TO MANY OPEN FILES\"\r\nvar N int = 12\r\n\r\n// Create the list of request\r\nfor i := 0; i \u003c 1000; i++ {\r\n    // Example python server, you can find under the \"example\" folder\r\n    req, err := requests.InitRequest(\"https://127.0.0.1:5000\", \"GET\", nil, nil, i%2 == 0) // Alternate cert validation\r\n    if err != nil {\r\n        log.Println(\"Skipping request [\", i, \"]. Error: \", err)\r\n    } else {\r\n        // If no error, we can append the request created to the list of request that we need to send\r\n        reqs = append(reqs, *req)\r\n    }\r\n}\r\n```\r\n\r\n```go\r\n// This array will contains the response from the given request\r\nvar response []datastructure.Response\r\n\r\n// send the request using N request to send in parallel\r\nresponse = requests.ParallelRequest(reqs, N)\r\n\r\n// Print the response\r\nfor i := range response {\r\n    log.Println(\"Request [\", i, \"] -\u003e \", response[i].Dump())\r\n}\r\n```\r\n\r\n## More example\r\n\r\nPlease, refer to the [example code](example/req_example.go)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiosavi%2Frequests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falessiosavi%2Frequests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiosavi%2Frequests/lists"}