Skip to main content

Pact badges

A pact badge says in one word whether the pacts of an application are verified, failing or unknown. Put it in a README, or let it appear on the project's page in Browse. Badges are public and need no token, so they are only served for a public project: one with a published, public version.

What the badge says​

Each pact is the latest one published between a consumer and a provider. Its state is the state of its newest verification result.

WordA pact is…An application is…
verifiedverified successfullyin at least one pact, and every pact is verified
failingfailing its newest verificationin any failing pact
unknownnot verified yetin no pact, or in a pact that has no result yet

An unverified pact never shows as verified.

Before you start​

  • The project is public: it has a published version that anyone can see in Browse.
  • The application is a pacticipant bound to that project. Bind it by choosing the project as its Linked project on its Settings tab, or by setting project to the project's slug when you create or update the pacticipant. A pacticipant that is not bound to a public project has no badge.

Add a badge to a README​

The quickest way is the pacticipant's Settings tab:

  1. Open the pacticipant and click the Settings tab.
  2. Under Badges, choose what the badge is For: the pacticipant (all its pacts), or one of its pacts.
  3. Check the preview. It is the SVG this page describes, read now as anyone would read it.
  4. Click Markdown, shields.io or Image URL, then the copy button, and paste it into the README.

The section needs the pacticipant's Linked project to be public. Without a linked project it says to link one; with a private one it says that the project serves no badge. See Add a badge.

To write the URL yourself, replace acme, ledger and ledger-api with the workspace slug, the project slug and the pacticipant slug.

![pact](https://api.example.com/v1/browse/tenants/acme/projects/ledger/pact-badges/pacticipants/ledger-api/badge.svg)

To judge one pair of applications, use the pact's own badge:

/v1/browse/tenants/acme/projects/ledger/pact-badges/pacts/provider/ledger-api/consumer/web/badge.svg

Either the provider or the consumer must be bound to the project.

Consumers on Browse and the portal​

The public project page in Browse shows a Pact verification strip: one badge for each bound pacticipant, a line such as 3 consumers · 2 verified · 1 failing, and the consumers themselves with the state of their pact. On the portal page of an API product, each project in the product's APIs list shows the same badges and consumer count, without the list of consumers.

A consumer is an application whose latest pact names the pacticipant as its provider. The page lists at most 20 consumers; the count is always the total. Only the consumer's name and a state word are shown. A project with no bound pacticipant, or a private project, shows nothing.

The same facts are in the public GET /v1/browse/tenants/{tenant}/projects/{project}/pact-badges response: each pacticipant has consumer_count and consumers (slug, name, status).

Use shields.io​

Every badge has a shields.json twin that follows the shields.io endpoint schema. Give shields.io its URL to style the badge as you like:

![pact](https://img.shields.io/endpoint?url=https%3A%2F%2Fapi.example.com%2Fv1%2Fbrowse%2Ftenants%2Facme%2Fprojects%2Fledger%2Fpact-badges%2Fpacticipants%2Fledger-api%2Fshields.json)

The document it reads looks like this:

{ "schemaVersion": 1, "label": "pact: ledger-api", "message": "verified", "color": "brightgreen" }

On the project page in Browse​

When a public project has pacticipants bound to it, its Browse page shows a Pact verification strip with one badge for each. A project with none shows nothing. The strip reads GET …/pact-badges, which lists every bound pacticipant with its state and badge URLs.

What is public​

Only a status word and the names of pacticipants you bound to a public project are shown. A private project, an unbound or unknown pacticipant, and a missing pact all answer the same 404, so a badge URL cannot be used to find out what exists. Answers may be cached for five minutes, so a badge can lag a new verification by that long.

The broker's own badge endpoints​

The Pact Broker has tag-aware badge endpoints (…/latest/badge, …/can-i-deploy/…/badge). Apiome does not serve them: they answer 501 and point to the public badges above. See Pact Broker compatibility.

Reference​

Browse REST reference — the five pact-badges routes.