Rivet Docs
  • Introduction
  • Consumer-Driven Contracts
  • Getting Started
  • Contracts
    • Configuration
    • Helpers
    • Composability
    • Publishing
  • CLI
  • Github
  • NPM
Powered by GitBook
On this page
  • Consumer-Driven Contracts
  • How it works
  • The client consumes the API

Was this helpful?

Consumer-Driven Contracts

PreviousIntroductionNextGetting Started

Last updated 5 years ago

Was this helpful?

Consumer-Driven Contracts

We'd like to introduce a strategy for keeping your applications [communication layer, APIs, etc..] in sync.

Read more about .

The primary actors involved are the consumer and the service:

  • Consumer — defines and publishes a contract using

  • Service — imports and satisfies a contract

How it works

The consumer maintains the contract for a given service.

  1. The consumer creates a contract for an endpoint in a given service.

  2. The consumer the contract to either an npm registry or git repository.

  3. The service requires the contract, via package.json, at a very specific version, from the consumer from an npm package.

  4. The service tests its API against the contract from the consumer.

  5. 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.

The client consumes the API

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.

Consumer-Driven Contracts
JSON Schema
publishes