Skip to content

pranavgawri/order-bff-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

Install specmatic package

npm install specmatic

Start BFF Server

This will start the Go BFF server

go run cmd/main.go

Note: When running this command you might get an error:

Could not find in. specmatic: specmatic-kafka:0.xx.yy.

You would have got this error because you don't have access to Specmatic Kafka. To fix this issue, reach out to us at [email protected] and we'll add you to our beta program and provide you access.

Access find orders api at http://localhost:8080/findAvailableProducts Note: Unless domain api service is running on port 9000, above requests will fail. Move to next section for solution!

Start BFF Server with Domain API Stub

  1. Download Specmatic Jar from github

  2. Start domain api stub server

java -jar specmatic.jar stub

Access find orders api again at http://localhost:8080/findAvailableProducts with result like

[{"id":698,"name":"NUBYR","type":"book","inventory":278}]

Run Tests

This will start the specmatic stub server for domain api using the information in specmatic.json and run the integration tests that expects the domain api at port 8090.

make integration_tests

OR

go test -v ./internal/tests/... -count=1 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published