Skip to main content
Contract testing verifies that an API provider honors the agreements (contracts) defined by its consumers. hitspec supports consumer-driven contract testing using standard .http files annotated with contract metadata.

How It Works

  1. Define expected interactions in .http files with contract annotations
  2. Run hitspec contract verify against a live provider
  3. hitspec sends each request and validates the response against your assertions

Contract Annotations

Add contract metadata to your requests using custom annotations:

Running Contract Verification

State Handlers

A state handler is an executable script that sets up the provider’s state before each interaction. hitspec calls it with the state description as an argument:

CLI Reference

Example Contract File

Keep contract files in a dedicated contracts/ directory, separate from your integration tests. This makes it clear which tests define API agreements vs. which tests validate behavior.
Last modified on February 10, 2026