{"id":37206820,"url":"https://github.com/byterio/hmock","last_synced_at":"2026-01-14T23:48:10.684Z","repository":{"id":304682721,"uuid":"1019479306","full_name":"byterio/hmock","owner":"byterio","description":"HTTP mock client for Go","archived":false,"fork":false,"pushed_at":"2025-09-30T14:31:30.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-30T16:26:42.822Z","etag":null,"topics":["go","golang","http","http-mock","http2","httpmock","mock","mocking","test","testing"],"latest_commit_sha":null,"homepage":"https://github.com/byterio/hmock","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/byterio.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-14T11:43:21.000Z","updated_at":"2025-09-30T14:31:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"aba0a48b-0f20-4945-bf5f-89cd971f2caa","html_url":"https://github.com/byterio/hmock","commit_stats":null,"previous_names":["byterio/hmock"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/byterio/hmock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byterio%2Fhmock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byterio%2Fhmock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byterio%2Fhmock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byterio%2Fhmock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byterio","download_url":"https://codeload.github.com/byterio/hmock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byterio%2Fhmock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439539,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["go","golang","http","http-mock","http2","httpmock","mock","mocking","test","testing"],"created_at":"2026-01-14T23:48:09.734Z","updated_at":"2026-01-14T23:48:10.669Z","avatar_url":"https://github.com/byterio.png","language":"Go","readme":"# HMock - HTTP Mock Client for Go\n\n[![Go Version][GoVer-Image]][GoDoc-Url] [![License][License-Image]][License-Url] [![GoDoc][GoDoc-Image]][GoDoc-Url] [![Go Report Card][ReportCard-Image]][ReportCard-Url]\n\n[GoVer-Image]: https://img.shields.io/badge/Go-1.24%2B-blue\n[GoDoc-Url]: https://pkg.go.dev/github.com/byterio/hmock\n[GoDoc-Image]: https://pkg.go.dev/badge/github.com/byterio/hmock.svg\n[ReportCard-Url]: https://goreportcard.com/report/github.com/byterio/hmock\n[ReportCard-Image]: https://goreportcard.com/badge/github.com/byterio/hmock?style=flat\n[License-Url]: https://github.com/byterio/hmock/blob/main/LICENSE\n[License-Image]: https://img.shields.io/github/license/byterio/hmock\n\nHMock is a lightweight, flexible HTTP mock client for Go that helps you test your HTTP-dependent code with ease.\n\n## Features\n\n✨ **Simple API** - Works with standard `http.Client` interface  \n🔧 **Customizable Responders** - Define mock responses for specific requests  \n📝 **Structured Logging** - Built-in support for `slog` logging  \n🚀 **Zero Dependencies** - Lightweight and easy to integrate  \n🧪 **Testing Friendly** - Perfect for unit and integration tests\n\n## Installation\n\n```bash\ngo get -u github.com/byterio/hmock\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io\"\n\t\"log/slog\"\n\t\"net/http\"\n\t\"strings\"\n\n\t\"github.com/byterio/hmock\"\n)\n\nfunc main() {\n\t// Create a mock client with custom responder\n\tmock := hmock.New(hmock.Config{\n\t\tResponder: func(req *http.Request) (*http.Response, error) {\n\t\t\treturn \u0026http.Response{\n\t\t\t\tStatusCode: http.StatusOK,\n\t\t\t\tBody:       io.NopCloser(strings.NewReader(\"Hello, HMock!\")),\n\t\t\t}, nil\n\t\t},\n\t\tLogger: slog.Default(),\n\t})\n\n\t// Use the mock client\n\tclient := mock.Client()\n\tresp, err := client.Get(\"https://example.com\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, _ := io.ReadAll(resp.Body)\n\tfmt.Println(string(body)) // Output: Hello, HMock!\n}\n```\n\n## Advanced Usage\n\n### Custom Response Based on Request\n\n```go\nmock := hmock.New(hmock.Config{\n\tResponder: func(req *http.Request) (*http.Response, error) {\n\t\tif req.URL.Path == \"/api/users\" {\n\t\t\treturn \u0026http.Response{\n\t\t\t\tStatusCode: http.StatusOK,\n\t\t\t\tBody:       io.NopCloser(strings.NewReader(`[{\"id\":1,\"name\":\"Byterio\"}]`)),\n\t\t\t\tHeader: http.Header{\n\t\t\t\t\t\"Content-Type\": []string{\"application/json\"},\n\t\t\t\t},\n\t\t\t}, nil\n\t\t}\n\t\treturn \u0026http.Response{\n\t\t\tStatusCode: http.StatusNotFound,\n\t\t\tBody:       http.NoBody,\n\t\t}, nil\n\t},\n})\n```\n\n### Error Simulation\n\n```go\nmock := hmock.New(hmock.Config{\n\tResponder: func(req *http.Request) (*http.Response, error) {\n\t\treturn nil, fmt.Errorf(\"network error\")\n\t},\n})\n```\n\n## Configuration Options\n\n| Option      | Description                                                              | Default Value                  |\n| ----------- | ------------------------------------------------------------------------ | ------------------------------ |\n| `Responder` | Function that generates responses for HTTP requests                      | Returns 200 OK with empty body |\n| `Logger`    | Optional `slog.Logger` for logging requests and responses (nil disables) | nil (disabled)                 |\n\n## Feedback and Contributions\n\nIf you encounter any issues or have suggestions for improvement, please [open an issue](https://github.com/byterio/hmock/issues) on GitHub.\n\nWe welcome contributions! Fork the repository, make your changes, and submit a pull request.\n\n## Support\n\nIf you enjoy using HMock, please consider giving it a star! Your support helps others discover the project and encourages further development.\n\n## License\n\nHMock is open-source software released under the Apache License, Version 2.0. You can find a copy of the license in the [LICENSE](https://github.com/byterio/hmock/blob/main/LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyterio%2Fhmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyterio%2Fhmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyterio%2Fhmock/lists"}