1.0.0 • Published 7 years ago

@itg/rivet v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 years ago

Rivet

Build status npm version

Docs | Issues

Introduction

We'd like to introduce a strategy for keeping your applications communication layer, apis, etc.. in sync. The pattern we'll be talking about is based on Consumer Driven Contracts.

The primary actors involved are the consumer and the producer:

  • Consumer  — defines and publishes a contract using JSON Schema
  • Producer — imports and satisfies a contract

The Problem

Everyone today has responsibility over applications that consume multiple APIs. Trouble arises when you'd like to make a change to an API without breaking other consumers.

People use tools like API Blueprint or slacker or tests within the API's code itself to specify the requirements for an API. However, these tools and strategies do not account for the consuming applications that may break. You can change a test with the APIs codebase and not know whether you've broken any given consumer.

Our strategy reverses this paradigm. When we allow the consumer to specify the requirements for an API (or producer), we can make changes to an producer and know immediately which consumers are compatible with that change. Additionally, we know when a version of an API can be retired, because we know when there are no more consumers of that API.

How it Works

The consumer maintains the contract for a given producer.

  1. The producer requires the contract, at a very specific version, from the consumer from an npm package.
  2. The producer tests its API against the contract from the consumer.
  3. 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.

npm.io

For example

Your client is a consumer app that defines the contract for its producer app: The API server.

The client consumes the API

Changes to server (or producer) 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 producer runs tests it verifies 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.