Client-Side CCD

Let's step through how to

In this section we will look at Contract Driven Development using Spring Cloud Contract (SCC) from the perspective of a (Angular) client side developer. We will see how to use the SCC docker images offers for validating an API fulfills the behaviors defined in the contracts and run a stub server based upon the contracts giving a stable backend for client developers to develop and test against.

Validate the Service with the Contracts

SCC offers a docker image springcloud/spring-cloud-contract:2.1.1.RELEASE for running contracts against an API to validate the API matches the behavior described in the contracts.

In the root contract-driven-developmentthere is the shell script in this script file you will want to update line 11, with your github repo location.

docker run --rm \
-e "PROJECT_NAME=produce-service" \
-e "" \
-e "REPO_WITH_BINARIES_URL=http://host.docker.internal:8081/artifactory/libs-release-local" \
-e "" \
-v "$(pwd)/build-output:/spring-cloud-contract-output/" \
-v "$(pwd)/contracts/:/contracts:ro" \

With that updated execute the script:

$ ./

Four of the five contracts should fail, but one of them, validate_find_produce_by_name_invalid_character will fail. From the root of contract-driven-development navigate to /build-output/reports/tests/test/index.html , this provides a report as to which tests failed and why. This can be helpful for debugging purposes.

If you update the second line of to the below (note you will be pointing to port 31417 instead of 31416), all the tests should pass.


Start the Mock API

Once all the contracts pass springcloud/spring-cloud-contract:2.1.1.RELEASE will generate an artifact in this case produce-service-0.0.1-stubs.jar. This artifact contains json files that can be read by a WireMock server to mock out a server that is actually addressable over HTTP. This is the stable backend mentioned at the intro to this section that client developers can use for developing and test against.

To run the stub server from the root of contract-driven-development execute the following:

$ ./

This will start up the mock service residing at http://localhost:9876/api/v1/produce.

Connect to Mock API and Real API

The angular application can be easily initialized to connect to either the mock API or the Real API.

To connect to the mock API run the following:

$ npm start:contract

To connect to the real API run the following:

npm run start:contract

The application will be available at http://localhost:4200. When connected to the real API you will see how the values returned are impacted by changes to state (new produce items being added) whereas the responses the angular app gets when calling the mock service always stay the same.