Heavily inspired by Jest Snapshot testing
Small command line tool that allows you to take "snapshots" of any given API endpoint and store the response. Using the start
command will spawn a server that will serve all previously stored endpoints.
npm install -g snapstub
Make sure you're in the desired folder to host your api mock files.
⬇️ Creates a new api stub:
snapstub add http://example.com/api/foo/bar
...create as many snapshots as you want.
🚀 Starts your mock server:
snapstub start
✨ Your endpoint will be locally available at: http://localhost:8059/api/foo/bar
If you want to save one or many different http methods, use the --method
flag:
snapstub add http://example.com/api/foo/bar --method=get,post,put
Using custom port and/or folder name:
export SNAPSTUB_FOLDER_NAME=my-mock-folder/
export SNAPSTUB_PORT=9000
snatstub start
By default snapshots will be saved in a __mocks__
folder that resolves from the current working directory, so make sure you run the commands from the correct project folder you desire.
NOTE: v1.0.x only supports json
endpoints.
snapstub wouldn't be possible without stubborn-server, go take a look at it if you need to support more complex scenarios.
MIT © Ruy Adorno