{"id":28289832,"url":"https://github.com/dillonstreator/roundtriphook","last_synced_at":"2025-10-10T22:42:13.170Z","repository":{"id":99153795,"uuid":"564974450","full_name":"dillonstreator/roundtriphook","owner":"dillonstreator","description":"utility for before \u0026 after hooks on an http.RoundTripper","archived":false,"fork":false,"pushed_at":"2022-11-25T00:28:03.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-13T06:41:26.260Z","etag":null,"topics":["golang","http-client","roundtripper","utility"],"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/dillonstreator.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":"2022-11-12T00:32:12.000Z","updated_at":"2022-11-16T01:52:06.000Z","dependencies_parsed_at":"2023-04-23T06:25:19.516Z","dependency_job_id":null,"html_url":"https://github.com/dillonstreator/roundtriphook","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dillonstreator/roundtriphook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Froundtriphook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Froundtriphook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Froundtriphook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Froundtriphook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dillonstreator","download_url":"https://codeload.github.com/dillonstreator/roundtriphook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillonstreator%2Froundtriphook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005458,"owners_count":26083902,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","http-client","roundtripper","utility"],"created_at":"2025-05-22T02:11:29.160Z","updated_at":"2025-10-10T22:42:13.152Z","avatar_url":"https://github.com/dillonstreator.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# roundtriphook\n\n[![codecov](https://codecov.io/gh/dillonstreator/roundtriphook/branch/main/graph/badge.svg?token=T4KLDSR6FH)](https://codecov.io/gh/dillonstreator/roundtriphook)\n\nutility package which provides a simple before \u0026 after hook interface for an `http.RoundTripper`\n\n## Install\n\n```sh\ngo get github.com/dillonstreator/roundtriphook\n```\n\n## Usage\n\n```go\nvar wrappedTransport = roundtriphook.NewTransport(\n\t// This call to roundtriphook.WithBaseRoundTripper is unnecessary\n\t// since the default behavior is to set the base round tripper to http.DefaultTransport if none is provided\n\troundtriphook.WithBaseRoundTripper(http.DefaultTransport),\n\troundtriphook.WithBefore(func(req *http.Request) *http.Request {\n\t\tfmt.Println(\"before request\")\n\t\t// mutate request or add context here\n\t\treturn req\n\t}),\n\troundtriphook.WithAfter(func(req *http.Request, res *http.Response, err error) {\n\t\tfmt.Println(\"after request\")\n\t}),\n)\n\nvar httpClient = \u0026http.Client{\n\tTransport: wrappedTransport,\n}\n```\n\n### logging transport\n\n```go\nvar loggingTransport = roundtriphook.NewTransport(\n\troundtriphook.WithBefore(func(req *http.Request) *http.Request {\n\t\tstartTime := time.Now()\n\t\tid := startTime.UnixNano()\n\n\t\tfmt.Printf(\"[%d] -\u003e %s %s\\n\", id, req.Method, req.URL)\n\n\t\tctx := req.Context()\n\t\tctx = context.WithValue(ctx, timeStartKey, startTime)\n\t\tctx = context.WithValue(ctx, idKey, id)\n\n\t\treturn req.WithContext(ctx)\n\t}),\n\troundtriphook.WithAfter(func(req *http.Request, res *http.Response, err error) {\n\t\tstartTime := req.Context().Value(timeStartKey).(time.Time)\n\t\tid := req.Context().Value(idKey).(int64)\n\n\t\tsb := strings.Builder{}\n\t\tsb.WriteString(fmt.Sprintf(\"[%d] \u003c- %s %s %s\", id, req.Method, req.URL, time.Since(startTime)))\n\n\t\tif res != nil {\n\t\t\tsb.WriteString(\" \" + res.Status)\n\t\t}\n\n\t\tif err != nil {\n\t\t\tsb.WriteString(fmt.Sprintf(\" %s\", err.Error()))\n\t\t}\n\n\t\tfmt.Printf(\"%s\\n\", sb.String())\n\t}),\n)\n```\n\n[full logging transport example](./examples/loggingtransport/main.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdillonstreator%2Froundtriphook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdillonstreator%2Froundtriphook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdillonstreator%2Froundtriphook/lists"}