Miss any of our Open RFC calls?Watch the recordings here! »

mocklocal

2.0.0 • Public • Published

mocklocal.js

npm version Build Status Coverage Status Dependencies Known Vulnerabilities

mocking an API server with random delays in the response

Installation

npm i -g mocklocal

Basic Usage

To start your mock server:

mocklocal

In separate terminal, you can try this example request

curl localhost:3000/example/mock/ -d '{"test":"1"}' -H "Content-Type: application/json"

Configurations

All these options can be configured through environment variables

Property Description Default value
PORT Port to serve the mock server 3000
MIN_DELAY Minimum delay for the mock server in seconds
you can also use floating point, with 3 fixed precision
0
MAX_DELAY Maximum delay for the mock server in seconds
you can also use floating point, with 3 fixed precision
3
RESPONSE Default response body for all requests
use req to reply back with the request
dont forget to escape your string if you're responding with JSON
req

Example usage with config:

PORT=5000 MIN_DELAY=0 MAX_DELAY=.5 RESPONSE={\"status\":\"ok\"} mocklocal

Usage with stdin

Examples of usage with stdin piped to mocklocal

echo '{"source":"stdin"}' | mocklocal
cat ./response_example.json | mocklocal

Note: using stdin as response will override value set in RESPONSE env variable

Tests

Used nyc, mocha, chai for tests; and coveralls for test coverage

npm test

Todos

  1. Enable floating point in delay (so we can have .1 seconds)
  2. response.json file as response

Install

npm i mocklocal

DownloadsWeekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

8.85 kB

Total Files

7

Last publish

Collaborators

  • avatar