This repository consists of two services fruit and botanical to illustrate and demo how to mock APIs. Both service can be built and run with docker. The wiremock directory consists of sample mock API responses for fruit and botanical
The service takes a fruit id and returns the botanical name of the fruit. > The service only returns botanical name for fruit with id 1
cd botanical
docker build -t botanical .
docker run -d -p 5000:5000 botanical
Access http://localhost:5000/api/v1/botanical?id=1 to view a sample response
NOTE: Run botanical service and fruit service on different servers to illustrate mocking different services on different instances
This service takes an id and returns a fruit
api/v1/fruits
return name, id, benefit and calories for a fruitapi/v2/fruits
call botanical service and returns name, id, benefit, calories and botanical_name for a fruit.
cd fruit
docker build -t fruit .
docker run -d -p 5000:5000 -e "BOTANICAL_SERVICE_URL=<<ENTER-BOTANICAL-HOST>>/api/v1" fruit
Access http://localhost:5000/api/v1/fruits?id=1 to view a sample response
- Clone wiremock docker repository
- Copy folders in wiremock/samples to wiremock-docker
cp -rf wiremock/samples/botanical wiremock-docker/samples
cp -rf wiremock/samples/fruit wiremock-docker/samples
cd wiremock-docker
docker build -t wiremock-botanical samples/botanical
docker run -it --rm -p 8080:8080 wiremock-botanical
cd wiremock-docker
docker build -t wiremock-fruit samples/fruit
docker run -it --rm -p 8081:8081 wiremock-fruit
- To test with wiremock, you can change the botanical service url to point to wiremock-botanical http://localhost:8080/api/v1/botanical
- Alternatively, you can use Charles Proxy to forward requests for a specific id from botanical service to wiremock-botanical