{"id":15439687,"url":"https://github.com/h2non/gentleman-mock","last_synced_at":"2025-09-12T03:19:56.425Z","repository":{"id":57483529,"uuid":"53031190","full_name":"h2non/gentleman-mock","owner":"h2non","description":"HTTP mocking for gentleman's clients made easy. Uses gock under the hood","archived":false,"fork":false,"pushed_at":"2017-09-11T08:41:26.000Z","size":11,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T04:41:02.089Z","etag":null,"topics":["golang","http","mock","mock-client","mock-server","mocking","stub"],"latest_commit_sha":null,"homepage":"https://github.com/h2non/gock","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/h2non.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":"2016-03-03T07:45:27.000Z","updated_at":"2023-02-09T12:07:11.000Z","dependencies_parsed_at":"2022-08-27T21:02:20.505Z","dependency_job_id":null,"html_url":"https://github.com/h2non/gentleman-mock","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2non%2Fgentleman-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2non","download_url":"https://codeload.github.com/h2non/gentleman-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249769255,"owners_count":21323061,"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","http","mock","mock-client","mock-server","mocking","stub"],"created_at":"2024-10-01T19:08:43.413Z","updated_at":"2025-04-19T18:48:10.545Z","avatar_url":"https://github.com/h2non.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [gentleman](https://github.com/h2non/gentleman)-mock [![Build Status](https://travis-ci.org/h2non/gentleman.png)](https://travis-ci.org/h2non/gentleman-mock) [![GoDoc](https://godoc.org/github.com/h2non/gentleman-mock?status.svg)](https://godoc.org/github.com/h2non/gentleman-mock) [![Coverage Status](https://coveralls.io/repos/github/h2non/gentleman-mock/badge.svg?branch=master)](https://coveralls.io/github/h2non/gentleman-mock?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/h2non/gentleman-mock)](https://goreportcard.com/report/github.com/h2non/gentleman-mock)\n\n[gentleman](https://github.com/h2non/gentleman)'s plugin for simple HTTP mocking via [gock](https://github.com/h2non/gock).\n\n## Installation\n\n```bash\ngo get -u gopkg.in/h2non/gentleman-mock.v2\n```\n\n## Versions\n\n- **[v1](https://github.com/h2non/gentleman-mock/tree/v1)** - First version, uses `gentleman@v1` and `gock@v1`.\n- **[v2](https://github.com/h2non/gentleman-mock/tree/master)** - Latest version, uses `gentleman@v2` and `gock@v1`.\n\n## API\n\nSee [godoc reference](https://godoc.org/github.com/h2non/gentleman-mock) for detailed API documentation.\n\n## Example\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n\n  \"gopkg.in/h2non/gentleman.v2\"\n  \"gopkg.in/h2non/gentleman-mock.v2\"\n)\n\nfunc main() {\n  defer mock.Disable()\n\n  // Configure the mock via gock\n  mock.New(\"http://httpbin.org\").Get(\"/*\").Reply(204).SetHeader(\"Server\", \"gock\")\n\n  // Create a new client\n  cli := gentleman.New()\n\n  // Register the mock plugin at client level\n  cli.Use(mock.Plugin)\n\n  // Create a new request based on the current client\n  req := cli.Request()\n\n  // Define base URL\n  req.URL(\"http://httpbin.org\")\n\n  // Define the URL path at request level\n  req.Path(\"/status/503\")\n\n  // Set a new header field\n  req.SetHeader(\"Client\", \"gentleman\")\n\n  // Perform the request\n  res, err := req.Send()\n  if err != nil {\n    fmt.Printf(\"Request error: %s\\n\", err)\n    return\n  }\n  if !res.Ok {\n    fmt.Printf(\"Invalid server response: %d\\n\", res.StatusCode)\n    return\n  }\n\n  fmt.Printf(\"Status: %d\\n\", res.StatusCode)\n  fmt.Printf(\"Header: %s\\n\", res.Header.Get(\"Server\"))\n}\n```\n\n## License\n\nMIT - Tomas Aparicio\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fgentleman-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2non%2Fgentleman-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2non%2Fgentleman-mock/lists"}