Wiremock Minimal Mock your APIs
_ ___ __
| | /| / (_)______ __ _ ___ ____/ /__
| |/ |/ / / __/ -_) ' \/ _ \/ __/ '_/
|__/|__/_/_/ \__/_/_/_/\___/\__/_/\_\
-> wiremock server started on :8000
docker pull prongbang/wiremock:latest
version: '3.7'
services:
app_wiremock:
image: prongbang/wiremock:latest
ports:
- "8000:8000"
volumes:
- "./mock:/mock"
environment:
- ORIGIN_ALLOWED=http://localhost:9000
$ docker-compose up -d
$ go install github.com/prongbang/wiremock/v2@latest
$ wiremock
$ wiremock -port=9000
https://github.com/prongbang/wiremock-example
Read doc gorilla/mux
project
├── docker-compose.yml
└── mock
├── login
│ └── route.yml
└── user
├── response
│ └── user.json
└── route.yml
POST http://localhost:8000/api/v1/login
Query
lang: "th"
Header
Api-Key: "ed2b7d14-3999-408e-9bb8-4ea739f2bcb5"
Body
{
"username": "admin"
"password": "pass"
}
- route.yml
routes:
login:
request:
method: "POST"
url: "/api/v1/login"
query:
lang: "th"
header:
Api-Key: "ed2b7d14-3999-408e-9bb8-4ea739f2bcb5"
body:
username: "admin"
password: "pass"
response:
status: 200
body: >
{"message": "success"}
GET http://localhost:8000/api/v1/user/1
POST http://localhost:8000/api/v1/user
- route.yml
routes:
get_user:
request:
method: "GET"
url: "/api/v1/user/{id:[0-9]+}"
response:
status: 200
body_file: user.json
create_user:
request:
method: "POST"
url: "/api/v1/user"
response:
status: 201
body: >
{"message": "success"}
*
- field required.
routes:
users:
request:
method: "POST"
url: "/api/v1/user"
query:
lang: "XYZ"
header:
Api-Key: "ABC"
cases:
user_accept_consent:
body:
action: "consent"
accept: "Y"
response:
status: 200
body_file: user-accept-consent.json
get_profile:
body:
username: "*"
userId: "*"
response:
status: 200
body_file: profile-self.json