Docs / Write contracts

Your first contract

What a contract file holds, with a provider and a consumer of the same endpoint.

On this page

A contract file is a YAML document that declares the resources a participant provides, the resources it consumes, and the schemas of their bodies. Both sides of an integration write the same format. The file holds only the declaration: the participant name and the version are flags of bidirekt publish, never keys in the file.

Example#

The provider petstore_api serves one pet by id:

yaml
provides:
  rest:
    /pets/*:
      get:
        responses:
          200: Pet

schemas:
  Pet:
    type: object
    properties:
      petId:
        type: integer
      name:
        type: string

The consumer petstore_web reads that pet, and from it only the name:

yaml
consumes:
  petstore_api:
    rest:
      /pets/*:
        get:
          responses:
            200: Pet

schemas:
  Pet:
    type: object
    properties:
      name:
        type: string

The two files have the same shape. provides holds what this participant serves, and consumes holds, under each provider's name, what it calls. schemas holds the bodies both sides name. The consumer declares only what it reads, so the provider is free to drop petId. All three keys are optional, and one file may carry both provides and consumes: a service in the middle of a chain declares both sides in the same contract.