Skip to main content

example-query-param

  • Spec V2: Query strings are stored as a string e.g. "query": "name=Polar".
  • Spec V3: Query strings are stored as Map (to an array) instead of strings e.g. "query": {"name": ["Polar"]}

See Pact Specification V3

Adding the query param(s) to the request:

await mockProvider.addInteraction({
state: "There are some bears",
uponReceiving: "A request for the Polar bear species by name",
willRespondWith: {
status: 200,
body: expectedResponse,
},
withRequest: {
method: "GET",
path: "/species",
query: { name: "Polar" },
},
});

Pacts

{
"consumer": {
"name": "BearServiceClient"
},
"provider": {
"name": "BearService"
},
"interactions": [
{
"description": "A request for the Polar bear species by name",
"providerState": "There are some bears",
"request": {
"method": "GET",
"path": "/species",
"query": "name=Polar"
},
"response": {
"status": 200,
"headers": {},
"body": {
"name": "Polar",
"colour": "White"
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}