In this tutorial we will use docker to run an instance of wiremock to setup a mock api for us to test our api’s.
Wiremock
Wiremock is a tool for building mock API’s which enables us to build stable development environments.
Docker and Wiremock
Run a wiremock instance with docker:
1
|
|
Then our wiremock instance will be exposed on port 8080 locally, which we can use to make a request against to create a api mapping:
1 2 3 4 |
|
The response should be something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Test Wiremock
If we make a GET request against our API:
1
|
|
Our response should be:
1 2 3 |
|
Export Wiremock Mappings
We can export our mappings to a local file named stubs.json
with:
1
|
|
Import Wiremock Mappings
We can import our mappings from our stubs.json
file with:
1
|
|
Resources
- https://wiremock.org/docs/docker/
- https://github.com/WireMock-Net/WireMock.Net/wiki/Admin-API-Reference
Thank You
Thanks for reading, feel free to check out my website, feel free to subscribe to my newsletter or follow me at @ruanbekker on Twitter.
- Linktree: https://go.ruan.dev/links
- Patreon: https://go.ruan.dev/patreon