httpmole provides a HTTP mock server that will act as a mole among your services, telling you everything http clients send to it and responding them whatever you want it to respond. Just like an actual mole.
Features:
- Use
response-statusandresponse-headerto quickly spin up a http server. - Use
response-fileto modify the response in real time using a text editor. - Use
response-fromto act as a proxy and be able to inspect the request/response going to a given service. - Cascade several calls using
/proxyreserved endpoint.
go install github.com/jcchavezs/httpmole/cmd/httpmole@latesthttpmole -p=8082 -response-status=200or using a response file:
httpmole -p=8082 -response-file=./myresponse.json// myresponse.json
{
"status_code": 200,
"headers": {
"content-type": "application/json"
},
"body": {
"message": "I am real"
}
}or proxying a service to inspect the incoming requests:
httpmole -p=8082 -response-from=therealservice:8082or proxying a cascaring call to different services to simulate a distributed transaction:
# terminal 1
httpmole -p=8081 -response-status=201
# terminal 2
httpmole -p=8082 -response-status=202
# terminal 3
httpmole -p=8083 -response-status=203and running
$ curl -i http://localhost:8081/proxy/localhost:8082/proxy/localhost:8083
HTTP/1.1 203 Non-Authoritative Information
Content-Length: 0
Date: Wed, 17 Jul 2024 08:51:00 GMT
Server-Timing: app;dur=0.00docker run -p "10080:10080" ghcr.io/jcchavezs/httpmole -response-status=201or pass a response file over volumes
docker run -p "10080:10080" -v `pwd`/response.json:/httpmole/response.json ghcr.io/jcchavezs/httpmole -response-file=/httpmole/response.jsonhttpmole is heavily inspired by httplab