Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 1.59 KB

README.md

File metadata and controls

31 lines (21 loc) · 1.59 KB

Specmatic Sample: GO BFF calling Domain API

This sample project demonstrates how we can practice contract-driven development and contract testing in a GO application that depends on an external domain service and Kafka. Here, Specmatic is used to stub calls to domain API service based on its OpenAPI spec and mock Kafka based on its AsyncAPI spec.

Here is the domain api contract/open api spec

Here is the AsyncAPI spec of Kafka that defines the topics and message schema.

Definitions

  • BFF: Backend for Front End
  • Domain API: API managing the domain model
  • Specmatic Stub/Mock Server: Create a server that can act as a real service using its OpenAPI or AsyncAPI spec

Background

A typical web application might look like this. We can use Specmatic to practice contract-driven development and test all the components mentioned below. In this sample project, we look at how to do this for GO BFF which is dependent on Domain API Service and Kafka demonstrating both OpenAPI and AsyncAPI support in specmatic.

HTML client talks to client API which talks to backend API

Tech

  1. Go (Gin)

Contract testing (Run Tests)

Using test containers (preferred)

go mod tidy
go test contract_test.go -v -count=1