A naive HTTP mock server with sequential responses from a text or json file.
1.7K
pretender
A naive HTTP mock server with sequential responses from a file.
❯ bin/pretender
██████╗ ██████╗ ███████╗████████╗███████╗███╗ ██╗██████╗ ███████╗██████╗
██╔══██╗██╔══██╗██╔════╝╚══██╔══╝██╔════╝████╗ ██║██╔══██╗██╔════╝██╔══██╗
██████╔╝██████╔╝█████╗ ██║ █████╗ ██╔██╗ ██║██║ ██║█████╗ ██████╔╝
██╔═══╝ ██╔══██╗██╔══╝ ██║ ██╔══╝ ██║╚██╗██║██║ ██║██╔══╝ ██╔══██╗
██║ ██║ ██║███████╗ ██║ ███████╗██║ ╚████║██████╔╝███████╗██║ ██║
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═════╝ ╚══════╝╚═╝ ╚═╝ v1.7.0
• starting server on port 8080
• using responses file: examples/example.json
• press ctrl+c to stop
With 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.7.0 --responses /examples/example.json
With curl
# change the os (linux or darwin) and arch (amd64 or arm64) based on your machine
curl -O https://github.com/kilianc/pretender/releases/download/v1.7.0/pretender-darwin-arm64.tar.gz
tar -xzf pretender-darwin-arm64.tar.gz
./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.json
The 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 pretender
Both 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 code
A JSON file allows more flexibility and controls:
[
{
"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
}
]
| 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 cover
After running make build the binary available in the bin/ folder
bin/pretender --port 8080 --responses examples/example.json
If you prefer to build and run pretender in a docker container, just on of these commands
make docker-build
make docker-run
MIT License, see LICENSE
Content type
Image
Digest
sha256:0dcca7be3…
Size
2.2 MB
Last updated
about 2 years ago
docker pull kilianciuffolo/pretender