This python script based on Tornado creates a mock server that always returns a 200 OK response and logs the request.
The request body can be logged as json or hex dump.
Code is based on this stackexchange comment
curl -X POST 127.0.0.1:8080 -d '{"id":1234, "message": "Hello World"}'
Json log
[BEGIN REQUEST]
127.0.0.1 HTTP/1.1 POST http://127.0.0.1:8080/
HEADERS
Accept: */*
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
Host: 127.0.0.1:8080
User-Agent: curl/7.64.1
BODY
{
"id": 1234,
"message": "Hello World"
}
[END REQUEST]
Hex dump log
[BEGIN REQUEST]
127.0.0.1 HTTP/1.1 POST http://127.0.0.1:8080/
HEADERS
Accept: */*
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
Host: 127.0.0.1:8080
User-Agent: curl/7.64.1
BODY
00000000: 7B 22 69 64 22 3A 31 32 33 34 2C 20 22 6D 65 73 {"id":1234, "mes
00000010: 73 61 67 65 22 3A 20 22 48 65 6C 6C 6F 20 57 6F sage": "Hello Wo
00000020: 72 6C 64 22 7D rld"}
[END REQUEST]
DISCLAIMER: Why Python? I'm not keen on untyped languages but this solution meets the "use just a script" requirement
- GET
- POST
- PUT
- PATCH
- DELETE
python request_dumper.py --h
usage: request_dumper.py [-h] [--port PORT]
[--body-print-format {json,hex_dump}]
optional arguments:
-h, --help show this help message and exit
--port PORT server port. Default value is 8080.
--body-print-format {json,hex_dump}
request body print format.
docker run -p80:8080 agrev/request_dumper:latest --body-print-format=json
docker build . -t request_dumper
docker run -p 80:8080 request_dumper
pip install -r requirements.txt
python -u ./request_dumper.py
PRs are more than welcome.