{"id":18787234,"url":"https://github.com/pantani/request","last_synced_at":"2025-08-09T17:05:17.346Z","repository":{"id":57563093,"uuid":"250863002","full_name":"Pantani/request","owner":"Pantani","description":"Client request abstraction.","archived":false,"fork":false,"pushed_at":"2021-04-17T17:24:05.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T13:23:05.069Z","etag":null,"topics":["client","golang","http","request"],"latest_commit_sha":null,"homepage":null,"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/Pantani.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":"2020-03-28T18:12:33.000Z","updated_at":"2021-04-17T17:23:36.000Z","dependencies_parsed_at":"2022-09-16T10:41:36.069Z","dependency_job_id":null,"html_url":"https://github.com/Pantani/request","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pantani%2Frequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pantani%2Frequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pantani%2Frequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pantani%2Frequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pantani","download_url":"https://codeload.github.com/Pantani/request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239707319,"owners_count":19684044,"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","request"],"created_at":"2024-11-07T20:53:55.704Z","updated_at":"2025-02-19T17:44:54.212Z","avatar_url":"https://github.com/Pantani.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/Pantani/request.svg)](https://pkg.go.dev/github.com/Pantani/request)\n[![codecov](https://codecov.io/gh/Pantani/request/branch/master/graph/badge.svg?token=BNDBT0HFFT)](https://codecov.io/gh/Pantani/request)\n\n# Client request abstraction\n\nSimple abstraction for client requests with memory cache.\n\nInitialize the client:\n```go\nimport \"github.com/Pantani/request\"\n\nclient := request.InitClient(\"http://127.0.0.1:8080\")\n// OR\nclient := request.Request{\n\tHttpClient:   request.DefaultClient,\n\tErrorHandler: request.DefaultErrorHandler,\n\tBaseUrl:      \"http://127.0.0.1:8080\",\n\tHeaders: map[string]string{\n\t\t\"Content-Type\": \"application/json\",\n\t\t\"Accept\":       \"application/json\",\n\t},\n}\n```\n## Methods\n\n### GET\n\n```go\nvar result CustomResult\nerr := client.Get(\u0026result, \"api/v1/object\", url.Values{\"id\": {\"69\"}})\n\n// with cache\nerr := request.GetWithCache(\u0026result, \"api/v1/object\", url.Values{\"id\": {\"69\"}}, time.Hour*1)\n```\n\n### POST\n\n```go\nvar result CustomResult\nerr := client.Post(\u0026result, \"api/v1/object\", Request{Name: \"name\", Id: \"id\"})\n\n// with cache\nerr := request.PostWithCache(\u0026result, \"api/v1/object\", Request{Name: \"name\", Id: \"id\"}, time.Hour*1)\n```\n\n## Parameters\n\n- Add Error Handler:\n```go\nclient.ErrorHandler = func(res *http.Response, desc string) error {\n\tswitch res.StatusCode {\n\tcase http.StatusBadRequest:\n\t\treturn getAPIError(res, desc)\n\tcase http.StatusNotFound:\n\t\treturn blockatlas.ErrNotFound\n\tcase http.StatusOK:\n\t\treturn nil\n\tdefault:\n\t\treturn errors.E(\"getHTTPError error\", errors.Params{\"status\": res.Status})\n\t}\n}\n```\n\n- Set timeout:\n```go\nclient.SetTimeout(35)\n```\n\n- Add header:\n```go\nclient.Headers[\"X-API-KEY\"] = \"\u003cAPI_KEY\u003e\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpantani%2Frequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpantani%2Frequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpantani%2Frequest/lists"}