Mocking for those pesky external web services
This project is maintained by wilig
A little HTTP server that will respond to a specific request with whatever canned response you'd like.
Mockity is a local stand-in web service that can simulate many of the real world problems that your application may face.
./mockity -conf=mockity.conf -port=8989
Just running mockity will use the defaults as listed. All configuration is done via a simple JSON configuration file.
Simple mocking:
[
{"request": {
"url": "/assets",
"method": "GET",
"response": {
"content-type": "application/json",
"status": 200,
"body": "{\"success\": true}"
}
}
}
]
How does it handle large response bodies you ask? See "Returning a file as a response body" below.
Getting more specific:
[
{"request": {
"url": "/assets",
"method": "POST",
"params": {"mockity": "mocks you!"},
"response": {
"content-type": "text/html",
"status": 200,
"body": "<html><head><title>Mock You!</title></head><body>Geek says what?</body></html>"
}
}
}
]
Even more specific:
[
{"request": {
"url": "/assets",
"method": "POST",
"params": {"mockity": "mocks you!"},
"headers": {"Accept": "*/*"},
"response": {
"content-type": "text/html",
"status": 200,
"body": "<html><head><title>Mock You!</title></head><body>You'll take anything?</body></html>"
}
}
}
]
Need to set a cookie?
...
"response": {
"cookies": {"cookie": "Yum Yum"}
...
}
Need to set a header?
...
"response": {
"headers": {"X-Mockity": ["Mocking you"]}
...
}
Returning a file as a response body
...
"response": {
"body": "!file:/path/to/file"
...
}
Specify a slow response. Response is written after the specified delay in ms.
...
"response": {
...
"!directive": {"delay": 1000}
}
Specify a hung server. It accepts connections but never responds. (Technically it will answer in about 10 years)
...
"response": {
...
"!directive": {"delay": -1}
}
Specify a response that prematurely closes the connection. Response headers and a random portion of the response body are output and the connection is closed.
...
"response": {
...
"!directive": {"partial": true}
}
Specify a response that redirects recursively
...
"response": {
...
"!directive": {"loop": true}
}
Specify a response that never terminates. It just keeps outputing data forever.
...
"response": {
...
"!directive": {"firehose": true}
}
Specify a response that works sometimes but not always.
...
"response": {
...
"!directive": {"flaky": true}
}
BSD licensed, see GitHub for details.