A naive HTTP mock server with sequential responses from a file.
❯ bin/pretender
██████╗ ██████╗ ███████╗████████╗███████╗███╗ ██╗██████╗ ███████╗██████╗
██╔══██╗██╔══██╗██╔════╝╚══██╔══╝██╔════╝████╗ ██║██╔══██╗██╔════╝██╔══██╗
██████╔╝██████╔╝█████╗ ██║ █████╗ ██╔██╗ ██║██║ ██║█████╗ ██████╔╝
██╔═══╝ ██╔══██╗██╔══╝ ██║ ██╔══╝ ██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗
██║ ██║ ██║███████╗ ██║ ███████╗██║ ╚████║██████╔╝███████╗██║ ██║
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝ ╚═╝ v1.8.0
• starting server on port 8080
• using responses file: examples/example.json
• press ctrl+c to stopWith go install
go install github.com/kilianc/pretender/cmd/[email protected]With docker
docker run --rm -it \
-p 8080:8080 \
-v $(pwd)/examples:/examples \
kilianciuffolo/pretender:v1.8.0 --responses /examples/example.jsonWith curl
export CURRENT_OS=$(uname -s | tr A-Z a-z)
export CURRENT_ARCH=$(uname -m | tr A-Z a-z | sed s/x86_64/amd64/)
export TARGZ_NAME="pretender-${CURRENT_OS}-${CURRENT_ARCH}.tar.gz"
export TARGZ_URL="https://github.com/kilianc/pretender/releases/download/v1.8.0/${TARGZ_NAME}"
curl -sOL ${TARGZ_URL}
tar -xzf ${TARGZ_NAME}
echo "successfully downloaded pretender $(./pretender --version)"Every response in examples/example.json will match one consecutive http response when hitting http://localhost:8080
pretender --port 8080 --responses examples/example.jsonThe server has a default /healthz endpoint that responds with a 200. If this conflicts with your mock responses, it is possible to configure it by setting the PRETENDER_HEALTH_CHECK_PATH environment variable.
PRETENDER_HEALTH_CHECK_PATH=/alive pretenderBoth plain text and JSON formats are supported.
A TEXT file contains one response per line:
This line is the first text/plain response body with 200 status code
This line is the second text/plain response body with 200 status codeA JSON file allows more flexibility and controls:
| name | description | default |
|---|---|---|
status_code |
HTTP status code | 200 |
body |
HTTP response body | "" |
headers |
HTTP headers | {"content-type":"text/plain"} |
delay_ms |
Number of ms to wait before responding | 0 |
repeat |
Number of times the response repeats or -1 for ∞ |
1 |
These are the usual suspects
make run
make build
make test
make coverAfter running make build the binary available in the bin/ folder
bin/pretender --port 8080 --responses examples/example.jsonIf you prefer to build and run pretender in a docker container, just on of these commands
make docker-build
make docker-runMIT License, see LICENSE

[ { "status_code": 200, "body": "hello", "headers": {"content-type":"text/plain"}, "delay_ms": 1000, "repeat": 5 }, { "body": { "hello": "world" }, "headers": {"Content-Type":"application/json"} }, // ... { "body": "will repeat forever", "repeat": -1 } ]