This directory serves two purposes:
- Example for C Providers: Demonstrates how to use the Pact FFI (Foreign Function Interface) in C to verify a provider implementation against consumer contracts.
- Reference for FFI Maintainers: Provides a working example for maintainers of libraries in other languages that use the Pact FFI internally, showing how to implement provider verification.
It includes utilities, example provider implementation, and contract verification code for both use cases.
include/: Header files for the provider codesrc/: Source files for the provider implementation:main.c: Main entry point that starts the HTTP server and runs verificationlogging.c,http_server.c: Utility implementationsprovider/: Provider-specific code including state handlers and HTTP endpoint handlers
CMakeLists.txt: CMake build configurationjustfile: Justfile for building and running the provider verificationconanfile.txt: Conan configuration for dependencies
This project uses Conan for dependency management and CMake for configuration and building. It also provides a justfile for convenience:
just runThe results of the verification tests are printed to stdout and will exit with a non-zero status if verification fails.
It assumes that the consumer contracts have already been generated by running the consumer tests in the c/consumer directory (or calling just run in the parent directory which runs both consumer and provider).
The verification tests require:
- A C and Rust compiler (Rust compiler requires nightly toolchain)
- CMake (version 3.24 or higher)
- Conan (version 2.0 or higher)
The CMake configuration will automatically build the Pact FFI library from the Rust source, hence the need for the Rust toolchain. In practice, you would typically download the pre-built binaries for your platform from the Pact FFI releases, and link against those instead.
All other dependencies (libmicrohttpd for HTTP server) will be automatically downloaded and/or built by Conan as needed.
If you don't have Conan installed, you can install it via uv:
uv tool install conanFor more installation options, see the Conan installation documentation.
Provider verification in Pact ensures that the provider implementation satisfies the contracts defined by consumers. The process:
- Start Provider: Launch the actual HTTP server that implements the provider API
- Configure Verifier: Set up the Pact verifier with provider details and contract files
- Setup Provider States: For each interaction, configure the provider to be in the required state (e.g., "user exists")
- Run Verification: The verifier replays each interaction from the contract against the running provider
- Report Results: Output verification results and any mismatches
This example demonstrates all these steps using the Pact FFI in C.