Local API stubs
Pact contracts are easily turned into locally running API stubs. Pact contracts lack advanced features such as predicates that you might find in tools like mountebank, however they are useful for many situations - such as e2e tests with tools like Protractor and Karma.
To get started, from your consumer code base you have a number of ways to run your API stubs outlined below.
Docker
Assuming you have a local directory containing your pact files at ./pacts
:
That's it!
See the project page for all available options.
CLI Tools
Download the Ruby CLI Tools and install into your PATH
.
Many of the language implementations will wrap the Ruby CLI Tools which contains the pact-stub-service
command.
The location of this will differ across OS and implementation, but is fairly trivial to find, for example, in pact-js
one can do the following to start stubs from npm run
commands.
package.json:
Running npm run stubs
will start a stub server on port 8080
for the given pact file(s) which you can then use for local development.
See more under "pact-stub-service" on the project page