Skip to content

Publishing and retrieving pacts

Matt Fellows edited this page May 15, 2020 · 25 revisions

Publishing

Pacts are published by making a PUT request to the path /pacts/provider/PROVIDER/consumer/CONSUMER/version/CONSUMER_VERSION_NUMBER with the pact json document as the body.

For example:

curl -v -XPUT \-H "Content-Type: application/json" \
-d@spec/pacts/a_consumer-a_provider.json \
http://your-pact-broker/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.0+4jvh387gj3

Or on Windows:

# Ensure TLS1.2 is set, otherwise it will default to TLS1.0 and you may be able to connect
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$res = Invoke-WebRequest -Uri "http://your-pact-broker/pacts/provider/A%20Provider/consumer/A%20Consumer/version/1.0.0+4jvh387gj3" -Method Put -InFile .\a_consumer-a_provider.json -ContentType "application/json"

You most likely won't need to get your hands dirty with curl however, as pact publishing is built in to most of the native pact libraries already. See the Language Support section of the documentation on "Sharing Pacts" on docs.pact.io to find out how to configure pact publishing in your language.

Please read about Pacticipant version numbers to ensure you are using the correct format.

Retrieving

Latest pact for a provider and consumer

If you are using an older broker, note that the "latest" pact may be determined by inspecting the consumer version number of the pact according to semantic versioning rules, not by the timestamp.

The following URL will return the latest pact between a specified consumer and provider. Keep reading however, as it is not necessarily the URL you should use for retrieving the pact to verify.

http://your-pact-broker/pacts/provider/PROVIDER/consumer/CONSUMER/latest

The latest endpoint returns the latest pact, regardless of tags. If you want to use tagging to enable you to effectively make "feature branch pacts" (RECOMMENDED!), then you should use one of the following two URLs to retrieve the "latest" pact for verification.

To retrieve the latest pact for a given tag (eg.master, prod or feature-x), use:

http://your-pact-broker/pacts/provider/PROVIDER/consumer/CONSUMER/latest/TAG

To retrieve the latest pact without any tags, use:

http://your-pact-broker/pacts/provider/PROVIDER/consumer/CONSUMER/latest-untagged

Latest pacts for a provider

http://your-pact-broker/pacts/provider/PROVIDER/latest

All latest pacts

http://your-pact-broker/pacts/latest

Use the built in HAL Browser at /hal-browser/browser.html to explore more endpoints in the pact broker.