{"id":17106783,"url":"https://github.com/maxcnunes/httpfake","last_synced_at":"2025-12-25T08:56:40.919Z","repository":{"id":272228988,"uuid":"915406923","full_name":"maxcnunes/httpfake","owner":"maxcnunes","description":"Httpfake – A Golang httptest wrapper for easily setting up a fake server","archived":true,"fork":true,"pushed_at":"2025-01-11T19:12:58.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-01-13T04:55:52.749Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"maxclaus/httpfake","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxcnunes.png","metadata":{},"created_at":"2025-01-11T19:07:22.000Z","updated_at":"2025-01-11T19:16:19.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/maxcnunes/httpfake","commit_stats":null,"previous_names":["maxcnunes/httpfake"],"tags_count":null,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxcnunes%2Fhttpfake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxcnunes%2Fhttpfake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxcnunes%2Fhttpfake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxcnunes%2Fhttpfake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxcnunes","download_url":"https://codeload.github.com/maxcnunes/httpfake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233694817,"owners_count":18715507,"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":["fake-server","fake-services","go","http","httptest"],"created_at":"2024-10-14T15:47:09.475Z","updated_at":"2025-09-20T23:32:52.995Z","avatar_url":"https://github.com/maxcnunes.png","language":"Go","readme":"httpfake\n========\n\n\u003cimg align=\"right\" width=\"125px\" src=\"https://raw.githubusercontent.com/maxcnunes/httpfake/master/logo/gopher-httpfake.png\"\u003e\n\n[![LICENSE](https://img.shields.io/badge/license-MIT-orange.svg)](LICENSE)\n[![Godocs](https://img.shields.io/badge/golang-documentation-blue.svg)](https://godoc.org/github.com/maxcnunes/httpfake)\n[![Build Status](https://travis-ci.org/maxcnunes/httpfake.svg?branch=master)](https://travis-ci.org/maxcnunes/httpfake)\n[![Coverage Status](https://coveralls.io/repos/github/maxcnunes/httpfake/badge.svg?branch=master)](https://coveralls.io/github/maxcnunes/httpfake?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/maxcnunes/httpfake)](https://goreportcard.com/report/github.com/maxcnunes/httpfake)\n\nhttpfake provides is a simple wrapper for [httptest](https://golang.org/pkg/net/http/httptest/) with a handful chainable API for setting up handlers to a fake server. This package is aimed to be used in tests where the original external server must not be reached. Instead is used in its place a fake server which can be configured to handle any request as desired.\n\n## Installation\n\n```\ngo get -u github.com/maxcnunes/httpfake\n```\n\nor\n\n```\ngovendor fetch github.com/maxcnunes/httpfake\n```\n\n\u003e If possible give preference for using vendor. This way the version is locked up as a dependency in your project.\n\n## Changelog\n\nSee [Releases](https://github.com/maxcnunes/httpfake/releases) for detailed history changes.\n\n## API\n\nSee [godoc reference](https://godoc.org/github.com/maxcnunes/httpfake) for detailed API documentation.\n\n## Assertions\n\nThere are built-in methods you can use to make assertions about requests to your HTTP handlers. The currently\nsupported assertions are:\n\n* Presence of query parameters\n* Query parameter and its expected value\n* Presence of HTTP headers\n* HTTP header and its expected value\n* The expected body of your request\n\n[WithTesting](https://godoc.org/github.com/maxcnunes/httpfake#WithTesting) **must** be provided as a server\noption when creating the test server if you intend to set request assertions. Failing to set the option\nwhen using request assertions will result in a panic.\n\n### Custom Assertions\n\nYou can also provide your own assertions by creating a type that implements the\n[Assertor interface](https://godoc.org/github.com/maxcnunes/httpfake#Assertor) or utilizing the\n[CustomAssertor function type](https://pkg.go.dev/github.com/maxcnunes/httpfake#CustomAssertor). The `Assertor.Log` method will be\ncalled for each assertion before it's processed. The `Assertor.Error` method will only be called if the\n`Assertor.Assert` method returns an error.\n\n## Examples\n\nFor a full list of examples please check out the [functional_tests folder](/functional_tests).\n\n```go\n// initialize the faker server\n// will bring up a httptest.Server\nfakeService := httpfake.New()\n\n// bring down the server once we\n// finish running our tests\ndefer fakeService.Close()\n\n// register a handler for our fake service\nfakeService.NewHandler().\n  Get(\"/users\").\n  Reply(200).\n  BodyString(`[{\"username\": \"dreamer\"}]`)\n\n// run a real http request to that server\nres, err := http.Get(fakeService.ResolveURL(\"/users\"))\n```\n\n## Contributing\n\nSee the [Contributing guide](/CONTRIBUTING.md) for steps on how to contribute to this project.\n\n## Reference\n\nThis package was heavily inspired on [gock](https://github.com/h2non/gock). Check that you if you prefer mocking your requests.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxcnunes%2Fhttpfake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxcnunes%2Fhttpfake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxcnunes%2Fhttpfake/lists"}