@nodezor/api-mock-mirror
v0.0.1
Published
Lightweight HTTP API recorder and playback mock mirror
Maintainers
Readme
@nodezor/api-mock-mirror
Lightweight in-memory HTTP API endpoint recorder and playback mock mirror.
The Problem
Building frontend features ahead of unreleased backend APIs or third-party integrations requires writing static JSON mocks that quickly become stale and inaccurate. Developers lack a lightweight proxy tool that captures real production/staging HTTP traffic and automatically records and serves identical, type-safe mock endpoints locally.
Features
- 📹 HTTP Traffic Recording: Captures endpoint path, HTTP method, status codes, and JSON response bodies.
- 🔄 Playback Matching: Instant path and method lookup during offline frontend development.
- ⚡ Zero External Dependencies: Powered by native JS primitives.
Installation
# pnpm
pnpm add @nodezor/api-mock-mirror
# npm
npm install @nodezor/api-mock-mirror
# yarn
yarn add @nodezor/api-mock-mirrorQuick Start / Usage Example
import { createMockMirror } from '@nodezor/api-mock-mirror';
const mirror = createMockMirror();
// Record endpoints during staging traffic capture
mirror.record('/api/v1/users/12', 'GET', 200, { id: 12, name: 'Alice' });
// Match requests during local offline development
const mockResponse = mirror.match('/api/v1/users/12', 'GET');
if (mockResponse) {
console.log(mockResponse.status); // 200
console.log(mockResponse.body); // { id: 12, name: 'Alice' }
}API Reference
createMockMirror(targetBaseUrl?: string)
Creates an in-memory HTTP recording and playback store.
Store Methods
record(url: string, method: HttpMethod, status: number, body: unknown, headers?: Record<string, string>): RecordedEndpointmatch(url: string, method?: HttpMethod): RecordedEndpoint | undefinedclear(): voidsize: number
License
MIT © PRX2112
