API mocking
API mocking replaces a real API with a stand-in that returns predefined responses. A developer can build against a payments or user service that is not ready yet, and tests can cover error cases that are hard to trigger for real. Mocks are often generated from an OpenAPI specification so they match the agreed contract.
How it works
A mock server listens on a URL and matches each request by method, path and sometimes body, then returns a stored response with a status code, headers and a payload.
For example, while the payments team is still building, a mock answers POST /payments with 201 {"status": "paid"}, and with 402 {"error": "card_declined"} when the amount is 0. The checkout team can now write and test both paths. When the real service ships, the same tests run against it.
Why it matters in production
Mocks drift. If the real API adds a field or changes an error code, tests against an old mock keep passing while production breaks. Generate mocks from the same spec the provider implements, or add contract tests, and run a smaller set of tests against the real service before release.
See also
On the One2N blog
References
