Registry / testing / rest-emulator-whyfly

rest-emulator-whyfly

JSON →
library0.0.4jsnpmunverified

A lightweight middleware for Express and Connect to emulate REST APIs for development and testing. Version 0.0.4 provides a simple configuration-driven approach to mock HTTP endpoints with support for GET, POST, query parameters, custom status codes, and timeouts. Supports modular mock file structures and presets for different response scenarios. Suitable for frontend development without a live backend, but limited to basic REST emulation without advanced features like dynamic responses, validation, or state management.

npm install rest-emulator-whyfly
INSTALL
IMPORT
SIG · REST-EMULATOR-WHYF
R
rest-emulator-whyfly
testingjavascriptv0.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const restEmulator = require('restEmulator');
import restEmulator from 'restEmulator';
The package uses CommonJS exports; ESM is not supported.
restEmulator (as function)
const restEmulator = require('restEmulator'); app.use(restEmulator(config));
app.use(require('restEmulator').default(config));
The module exports the middleware function directly, not as a default export.
Mock configuration
module.exports = { '/api/users': { data: [] } };
export default { '/api/users': { data: [] } };
Mock files use CommonJS module.exports; ES module syntax is not supported.

Sets up an Express server with rest-emulator-whyfly middleware to mock two endpoints with static data and query support.

const express = require('express'); const restEmulator = require('rest-emulator-whyfly'); const config = { '/api/users': { data: [ { name: 'John' }, { name: 'Adam' } ] }, '/api/cities': { data: [ { name: 'New York' }, { name: 'Miami' } ], query: { 'name=Miami': { data: [ { name: 'Miami' } ] } }, code: 200, timeout: 5000 } }; const app = express(); app.use(restEmulator(config)); app.listen(3000, () => console.log('Server running on port 3000'));
Debug
Known issues
breakingModule exports the middleware function directly; common mistake is to import as default or access .default.
fix
Use const restEmulator = require('rest-emulator-whyfly');
affects: >=0.0.1
gotchaQuery parameters matching is exact string comparison; spaces or encoding mismatches will fail to match.
fix
Ensure query string in config matches the exact format as sent by the client (e.g., 'name=Miami' not 'name=Miami&' ).
affects: >=0.0.1
gotchaTimeout value is in milliseconds; setting timeout to 0 means no delay, not infinite.
fix
Use 0 for immediate response or a positive integer for delay.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: restEmulator is not a function
Incorrect import: using ESM import or destructuring instead of require.
fix
Use const restEmulator = require('rest-emulator-whyfly');
Cannot find module 'restEmulator'
The package is published as 'rest-emulator-whyfly', but code requires 'restEmulator'.
fix
Require 'rest-emulator-whyfly' instead of 'restEmulator'.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies
expressoptionalRequired as the middleware is designed for Express/Connect
Agent activity
6 hits · last 30 days
node
6
Resources
rest-emulator-whyfly — npm install rest-emulator-whyfly · libregistry