DEV Community

137Foundry
137Foundry

Posted on

Seven Free Tools for Mocking Flaky Third-Party APIs in Staging

Why Mocking Failure Matters More Than Mocking Success

Most API mocking setups exist to unblock frontend work while a backend endpoint isn't ready yet, and they mock the happy path exclusively. That's useful, but it skips the scenario that actually breaks pipelines in production: the timeout, the mixed-status batch response, the mid-request connection drop. If your mocking setup can't simulate those, your tests can't catch the bugs that show up the first time a real vendor API has a bad day. These seven tools all support failure simulation, not just canned success responses.

1. Postman Mock Servers

Postman mock servers let you define example responses per endpoint, including error statuses and delayed responses, directly from a collection you're probably already using to test the real API. It's the lowest-friction option if your team already lives in Postman, since there's no separate tool to learn. The mock server also supports dynamic response rules, so you can return a success on the first call and a failure on the second, which is exactly the shape a mid-batch failure takes in production.

2. WireMock

WireMock runs as a standalone server and supports fault injection specifically, including connection resets, empty responses, and random data corruption, not just configurable status codes. It's a strong choice when you need to simulate genuinely broken connections rather than just an API that returns an error politely. It also runs well inside a CI container, which matters if you want failure scenarios exercised on every pull request rather than only when someone remembers to run them manually.

3. Mockoon

Mockoon is a desktop app for building mock APIs with a GUI, and it supports per-route response rules including random failure injection and latency simulation. It's a good fit for teams that want a visual editor rather than writing mock definitions by hand, and its rule sets can be exported and version-controlled alongside the rest of the codebase so the mock behavior stays in sync with the real API's evolving contract.

4. Hoverfly

Hoverfly can record real API traffic and replay it later, including replaying the exact failure responses a vendor sent during a real incident. This makes it particularly useful for reproducing a specific production bug in a controlled staging environment instead of guessing at what the vendor's failure looked like. Because it captures the real payloads involved, it also tends to catch schema-shape assumptions your handwritten mocks might have missed.

5. Toxiproxy

Toxiproxy sits at the network layer and injects latency, bandwidth limits, and connection resets between your service and any dependency, API included. Because it works below the application layer, it's especially good for testing timeout handling and connection-pool behavior that response-level mocks can't reach. It's also the tool of choice for verifying that a circuit breaker actually trips under sustained connection failure, rather than just under a clean error response.

6. json-server

json-server spins up a full REST API from a JSON file in seconds, and combined with custom middleware it can be configured to fail a percentage of requests randomly. It's a lightweight option when you need a working mock API fast and don't need the more elaborate fault-injection features of a dedicated tool. For smaller teams or early-stage pipelines, this is often the fastest way to get any failure simulation running at all, even if you graduate to something more specialized later.

7. Webhook.site

Webhook.site is built for testing webhook consumers rather than outbound API calls, letting you inspect exactly what a webhook payload looks like and manually trigger redeliveries. It's the right tool specifically when the flaky integration you're worried about is inbound, a vendor calling you, rather than your pipeline calling them. It's particularly useful for confirming that your webhook handler behaves correctly when the same event gets redelivered, which is a scenario nearly every vendor's retry policy eventually triggers.

A Simple Rollout Plan

If none of this exists in your pipeline yet, don't try to adopt all seven tools at once. Start with whichever one maps most directly to the failure mode you're most worried about right now. If you've had a recent incident involving a vendor timeout, start with Toxiproxy. If it was a malformed response causing a downstream crash, start with WireMock or Mockoon. Get one failure scenario under test, confirm it actually catches a regression by deliberately breaking your retry logic and watching the test fail, and then expand to the next scenario.

This incremental approach beats a big-bang "let's build a whole fault-injection test suite" project, which tends to stall out before it ships anything usable. A single working failure test this week beats a comprehensive plan that never gets past the planning doc.

What Happens If You Skip This Step

Teams that skip failure-mode mocking entirely tend to discover their retry logic's bugs the same way: in production, during an actual vendor outage, at the worst possible time to be debugging. A retry loop that doesn't back off correctly, a circuit breaker that never trips, a dead-letter path that silently drops the payload instead of storing it, these are all things a five-minute mocked failure test would have caught in an afternoon instead of an incident review.

The cost asymmetry is the whole argument here. Setting up one of these tools and writing a handful of failure-scenario tests takes an afternoon. Debugging the same gap during a live vendor outage, with customers affected and a postmortem to write afterward, takes considerably longer and costs a lot more trust.

Picking the Right One for Your Stack

For most teams building a data ingestion pipeline, a combination of two of these covers the bases: something like WireMock or Mockoon for response-level failure simulation, and Toxiproxy for the network-level failures that response mocking can't reach. Trying to standardize on one tool for every kind of failure usually means picking the wrong tool for at least one of the scenarios that matters.

"The pipelines that survive a real vendor outage are almost always the ones where someone deliberately simulated a bad outage in staging first. It's a small investment that pays for itself the first time it isn't a drill." - Dennis Traina, founder of 137Foundry

Building This Into Your Regular Test Suite

A fault-injection mock is only useful if it runs regularly, not just once during initial integration testing. Wire the failure scenarios into your existing CI pipeline as a scheduled or pre-deploy check, so a change to your retry logic or dead-letter handling gets validated against simulated failure automatically, the same way your unit tests validate the happy path automatically.

Where This Fits the Bigger Picture

Mocking failure well is what makes it possible to trust that your retry classification, circuit breakers, and dead-letter handling actually work before a real outage tests them for you. 137Foundry's data integration team builds this kind of failure-aware testing into ingestion pipelines from the start rather than retrofitting it after an incident, and the longer guide on handling partial API failures gracefully covers the architecture these tools are meant to validate.

Pick one tool from this list, wire a single failure scenario into your test suite this week, and expand from there. The goal isn't total coverage on day one, it's making sure the next vendor outage is something your tests already rehearsed. Revisit the list every few months too, since new failure patterns tend to surface as your integrations mature and vendors change their own infrastructure underneath you.

Top comments (0)