This tool helps developers to continue their task independently of API availability. The developer just needs to route all their API request through this tool and it will cache the response and return mocked response in case of errors.
npm install -g api-mock-proxy
now you can run your mock proxy as
api-mock-proxy -p 8000 -t http://your.api.com
now your proxy server is ready at http://localhost:8000. Just use this URL in all client and you will get the response from http://your.api.com. The best part is, it will return a mocked response if actual API is not working.
port or -p: (default:8080) -
To specify the port to which mock server will listen
targetUrl or -t: (default:http://localhost:80) -
To specify the target URL where the mock server will forward all requests and return the response back. This will be URL for your actual API and the mock server will save the response for mocking when API responds with an error
errorCodes or -e: (default:*) -
this will provide options for mocking on errors, error code will be provided in comma separated list like
404,500,ECONNREFUSED. Default value is
* which means it will return mocked response for any error unless mode in not record.
mode or -m: (default:mix) -
It can take any of the three values mock|record|mix
mock: mock all the request no need to call actual API
record: always return response from actual API and create a cache for future mocking
mix: Call the actual API and return actual response except error code passed as
dataPath or -d: (default:./data.json) -
path for the mock data, it should be a valid data file.
For the first time just specify the path and mock will be created at that location.
For running in mock mode there must be pre-populated mock data.
use this to enable cors header for all origin, methods and headers
provide a string to be used in response header 'Access-Control-Allow-Origin'
provide a string to be used in response header 'Access-Control-Allow-Methods'
provide a string to be used in response header 'Access-Control-Allow-Headers'
provide a string to be used as Key for https server, https server will be created only if both key and certificates are provided
provide a string to be used as Certificate for https server
provide pat for the Key file to be used for https server
provide pat for Certificate file to be used for https server