liveBook · Manning

External mock API

As explained in Automating API Delivery

A mock API, or API simulation, is a simulated API that accepts representative requests and returns representative responses without requiring the actual API implementation.

An external mock API simulates a third-party API that your team does not control. It accepts representative requests and returns responses that let an application team develop and test an integration without depending on the real service. This is useful when the third-party API is unavailable or unstable, difficult to provision, expensive to call, or subject to a request quota. section 9.2 section 9.2.2

Choose the simulation and where it runs according to the test:

  • Use canned responses for an early integration check. They are predictable, but can become repetitive or outdated. section 9.2 section 9.2.2
  • Use dynamic responses or a configurable mock to exercise varied data, success cases, and errors. Mocks can also support tests of conditions such as high latency or random failures. section 9.2.2 section 9.2.1
  • Run the mock locally for low-latency or offline work, or host it when multiple people, teams, or applications need access. Hosting location does not determine whether the API being simulated is external. section 9.2.2

Try the response modes

An illustrative Prism workflow uses an OpenAPI file: run `prism mock chapter8/apis/product-catalog.oas.yaml`, then request `http://localhost:4010/v1/catalog/categories` with `Accept: application/vnd.api+json` and `Authorization: Bearer my-secret-token`. Repeated requests return the same static response. Restart with `prism mock --dynamic chapter8/apis/product-catalog.oas.yaml`; repeated responses keep the same schema or shape but contain different values. This example demonstrates the mechanics, not a third-party API; an external mock simulates an API your team does not own. section 9.2.2

Use mocks to isolate automated tests from unreliable, costly, or restricted dependencies and to let client development proceed alongside API implementation. A sandbox is different: it runs an actual API implementation in a controlled environment. section 9.2.1 section 9.2

How Automating API Delivery covers it

How deep it goes
Defines external mocks, distinguishes simulation types and response modes, and demonstrates Prism commands without a third-party-specific walkthrough.
Examples
Uses Prism and curl with a product-catalog OpenAPI file to compare repeated static responses with varying dynamic values.
What it assumes
Assumes familiarity with API requests; supplies an OpenAPI file and request details for the Prism example.
What you can do after
Apply it via Prism to simulate OpenAPI-defined responses and choose local or hosted access for integration work.
How it connects
Connects API simulations to OpenAPI definitions, stub APIs, sandbox APIs, design-first development, and test isolation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Automating API Delivery. The section links point to the parts of the book it draws on.