In microservices, we have several services that are independent or services that require communication with each other. Apart from this, from a user's (here, the user is a developer, who is consuming the API being referred to) point of view, they know about the service and whether it has, or doesn't have, several clients/consumers/users. These clients can have the same or different needs.
Consumer-driven contracts refer to a pattern that specifies and verifies all the interactions between clients/consumers and the API owner (application). So here, consumer-driven means that the client/consumer specifies what kind of interactions it is asking for with the defined format. On the other hand, the API owner (application services) must then agree to these contracts and ensure that they are not breaking them:
These are the contracts:
- Provider contract: This is merely a complete description of the service provided by the API owner (application). Swagger's documentation can be used for our REST API (web API).
- Consumer contract: This is a description of how consumers/clients are going to utilize the provider contract.
- Consumer-driven contract: This is a description of how the API owner satisfies consumer/client contracts.