stateful-mock-http-proxy

0.0.4 • Public • Published

Stateful mock http proxy

The goal of this small express app is to mock json responses from API or other mocks in testing environments.

TLDR

1 - Run the proxy providing the url of the API to mock

Using docker :

docker run -it -p 3000:3000 -e TARGET=http://whatever.api sportrizer/stateful-mock-http-proxy

Using nodejs :

export TARGET=http://whatever.api && npm run start

http://whatever.api will be proxified to http://localhost:3000/api

2 - Add a mock to be consumed in the next api call

curl --request POST \
  --url http://localhost:3000/mock \
  --header 'Content-Type: application/json' \
  --data '{
    "url": "/resource",
    "method": "GET",
    "json" : {
      "my-custom": "response"
    }
  }'

3 - future calls to the api will be mocked

curl --request GET \
  --url http://localhost:3000/api/resource

results in : {"my-custom": "response"} only one time (headers and status code are followed).

Readme

Keywords

Package Sidebar

Install

npm i stateful-mock-http-proxy

Weekly Downloads

1

Version

0.0.4

License

MIT

Unpacked Size

7.4 kB

Total Files

8

Last publish

Collaborators

  • brewal