Consumer-Driven Contracts
Last updated
Last updated
We'd like to introduce a strategy for keeping your applications [communication layer, APIs, etc..] in sync.
Read more about Consumer-Driven Contracts.
The primary actors involved are the consumer and the service:
Consumer — defines and publishes a contract using
Service — imports and satisfies a contract
The consumer maintains the contract for a given service.
The consumer creates a contract for an endpoint in a given service.
The consumer publishes the contract to either an npm registry
or git repository.
The service requires the contract, via package.json
, at a very specific version, from the consumer from an npm package.
The service tests its API against the contract from the consumer.
If the contract tests fail, it means the contracts and the consumer application need to be updated to ensure that the consumer continues to work as expected.
Your client is a consumer app that defines the contract for its service app: The API server.
Changes to server (or service) responses can potentially break the client (or consumer) without API developers knowing about the breaking changes. To prevent this, the consumer publishes a contract that it expects the API to satisfy. When the service runs tests, it verifies that its responses will satisfy the consumer’s needs. If the responses don’t satisfy the consumer's needs, we know that the consumer won’t work as expected after the changes are published. This visibility aids in preventing us from deploying breaking changes.