WireMock is for me an alternative for Postman, especially when I don’t want to share 3rd party APIs over the network (even with private token). Stubbing requests is quite easy, we can use a standalone version of WireMock and keep all stubs in mappings (stubbing GET requests is even simpler we can just put responses in __files/path/to/resource/home.html).
Then run from folder we have mappings or __files :java -jar wiremock-standalone-2.21.0.jar --port 9999
The sample mapping for POST api request can look like:
# Response we want to get
{
"id": 123,
"login": "test@example.com",
"country": "us",
"status": "active,
"messages": [
{
"id": 56,
"text": "Product was saved"
},
{
"id": 59,
"text": "Email has been sent to customer"
}
]
}
# Mapping in file mappings/login.json
{
"request": {
"method": "POST",
"url": "/api/login"
},
"response": {
"status": 200,
"body": "{\n \"id\": 123,\n \"login\": \"test@example.com\",\n \"country\": \"us\",\n \"status\": \"active,\n \"messages\": [\n {\n \"id\": 56,\n \"text\": \"Product was saved\"\n },\n {\n \"id\": 59,\n \"text\": \"Email has been sent to customer\"\n }\n ]\n}",
"headers": {
"Content-Type": "application/json"
}
}
}