Skip to main content

Pact Contract Builder

Build consumer-driven contract test JSON for the Pact framework. Define consumer and provider names, add HTTP interactions with request/response pairs and provider states, then generate and download a valid Pact JSON contract file. Supports Pact Spec v2, v3, and v4. All generation runs in your browser.

✓ Pact Spec v2/v3/v4 ✓ Provider states ✓ Download .json

Frequently Asked Questions

What is consumer-driven contract testing?▼

Consumer-driven contract testing (CDCT) is an approach where the consumer of an API defines the contract — what requests it makes and what responses it expects. The provider then verifies it can satisfy those contracts. This ensures API changes don't silently break consumers, catching integration bugs before they reach production.

What is Pact and how does it work?▼

Pact is the most popular CDCT framework. The consumer runs tests against a mock server that records interactions into a Pact file (JSON contract). That file is shared with the provider (via Pact Broker or directly), and the provider verifies it can satisfy all interactions. Both sides are tested independently, avoiding the need for a shared test environment.

What is a provider state?▼

A provider state describes the precondition the provider needs to be in for a given interaction to succeed — for example, 'a user with id 123 exists'. When the provider runs verification, it reads the provider state and sets up the necessary data before replaying the request. Without provider states, the provider has no way to know how to prepare for the test.

What is the difference between Pact v2, v3, and v4?▼

Pact v2 is the most widely supported spec and covers basic request/response contracts. Pact v3 adds support for message-based interactions (Kafka, SNS, queues) and provider states as parameters. Pact v4 adds support for asynchronous interactions, plugins, and combined HTTP + message contracts in a single file. For REST APIs, v2 or v3 is sufficient.

How do I use the generated Pact contract?▼

Save the JSON file and point your Pact consumer test framework at it (e.g. in Jest: PactV2.fromFile('./contract.json')). For provider verification, publish the contract to a Pact Broker or share the file directly, then run provider tests with the Pact verifier library for your language (Ruby, Go, Java, JS, etc.).

What is a Pact Broker?▼

A Pact Broker is a shared server that stores and retrieves Pact contract files. It lets teams share contracts between consumer and provider CI pipelines automatically, tracks contract compatibility by version, and can block deployments if contracts are broken. PactFlow (pactflow.io) is the hosted SaaS version; you can also self-host the open-source pact-broker.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →