Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. httpmock

httpmock

MITGov1.4.1

A Go library for easy mocking of HTTP responses from external resources in tests.

Visit WebsiteGitHubGitHub
2.1k stars106 forks0 contributors

What is httpmock?

httpmock is a Go library for mocking HTTP responses from external APIs and services in tests. It allows developers to isolate their code from network dependencies, enabling faster and more reliable unit tests by simulating API interactions.

Target Audience

Go developers writing unit tests for applications that make HTTP requests to external services, such as REST APIs or third-party integrations.

Value Proposition

Developers choose httpmock for its simplicity, intuitive API, and seamless integration with Go's standard testing package, go-testdeep/tdsuite, and Ginkgo, without adding unnecessary complexity.

Overview

HTTP mocking for Golang

Use Cases

Best For

  • Unit testing Go applications that depend on external HTTP APIs without making real network calls.
  • Mocking REST API responses with exact URL matching or regex patterns for flexible test scenarios.
  • Tracking and verifying HTTP call counts and details during test execution for assertions.
  • Integrating with testing frameworks like Ginkgo or go-testdeep/tdsuite for structured test suites.
  • Generating dynamic mock responses based on request parameters using custom handler functions.
  • Testing HTTP clients, such as those built with Resty, by mocking their transport layer.

Not Ideal For

  • Projects requiring mocking of non-HTTP protocols like gRPC or WebSockets
  • Teams needing built-in support for API contract testing with OpenAPI specifications
  • Applications with complex stateful API simulations that require persistent session management without manual implementation

Pros & Cons

Pros

Flexible URL Matching

Supports both exact URLs and regex patterns, enabling precise or broad mocking scenarios as shown in the simple example with `=~^https://api\.mybiz\.com/articles/id/\d+\z`.

Easy Response Creation

Provides helpers like NewStringResponder and NewJsonResponder to quickly mock responses with custom status codes, headers, and bodies, reducing boilerplate in tests.

Seamless Test Integration

Integrates naturally with Go's standard testing package, go-testdeep/tdsuite, and Ginkgo, with clear examples for each framework in the README.

Call Tracking and Verification

Allows monitoring of HTTP call counts and details via GetCallCountInfo, useful for assertions in unit tests to verify external API interactions.

Cons

Non-Default Client Boilerplate

Requires additional setup for custom HTTP clients like Resty, as shown in the Ginkgo example with ActivateNonDefault, adding complexity and potential for errors.

Limited to HTTP Mocking

Only handles HTTP requests, so projects using other protocols such as gRPC must find separate mocking solutions, increasing dependency management.

No Built-in Concurrency Safety

The README doesn't address thread-safety or handling concurrent requests, which could lead to flaky tests in parallel testing environments.

Frequently Asked Questions

Quick Stats

Stars2,077
Forks106
Contributors0
Open Issues5
Last commit28 days ago
CreatedSince 2014

Tags

#test-isolation#unit-testing#integration-testing#go-library#api-mocking#testing#go#http-mocking

Built With

G
Go

Links & Resources

Website

Included in

Go169.1k
Auto-fetched 1 day ago

Related Projects

mockerymockery

A mock code autogenerator for Go

Stars7,125
Forks454
Last commit1 month ago
go-sqlmockgo-sqlmock

Sql mock driver for golang to test database interactions

Stars6,553
Forks410
Last commit1 year ago
gomockgomock

GoMock is a mocking framework for the Go programming language.

Stars3,359
Forks168
Last commit5 months ago
hoverflyhoverfly

Lightweight service virtualization/ API simulation / API mocking tool for developers and testers

Stars2,497
Forks227
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub