@thaparoyal/replayapi
v0.1.4
Published
ReplayAPI SDK for Node.js — Capture HTTP traffic automatically
Maintainers
Readme
@replayapi/node
ReplayAPI SDK for Node.js — Automatically capture outgoing HTTP traffic for replay testing.
Install
npm install @replayapi/nodeQuick Start
import { replayApi } from '@replayapi/node'
// Initialize once at app startup
replayApi.init({
apiKey: process.env.REPLAY_API_KEY!,
environment: 'staging',
})
// That's it — all http, https, and fetch calls are now capturedConfiguration
replayApi.init({
// Required
apiKey: 'rp_your_api_key',
// Optional
proxyUrl: 'http://localhost:8080', // Default proxy URL
environment: 'staging', // Environment label
sessionId: 'user-checkout-flow', // Group related requests
// Filter what gets captured
include: ['api.example.com', /\/api\/v\d+\//],
exclude: ['healthcheck', /\.internal\./],
// Debug
debug: true, // Enable verbose logging
disabled: false, // Disable without removing code
timeout: 30000, // Proxy request timeout (ms)
})API
replayApi.init(config)
Initialize the SDK. Patches http.request, https.request, and fetch globally.
replayApi.stop()
Stop capturing and restore original HTTP behavior.
replayApi.isActive()
Returns true if the SDK is currently intercepting traffic.
replayApi.getStats()
const stats = replayApi.getStats()
// { totalCaptured: 42, totalSkipped: 3, totalErrors: 0, startedAt: Date }How It Works
- Your app makes an HTTP request:
GET https://api.example.com/users - The SDK rewrites it to:
GET http://proxy:8080/userswith headers:X-Api-Key: rp_...(your API key)X-Replay-Target: https://api.example.com(original target)X-Replay-Env: staging(environment)
- The proxy captures the traffic, forwards to the target, returns the response
- Your app receives the response as if the proxy wasn't there
Supported
- Node.js 18+ (native
fetchsupport) http.request/http.gethttps.request/https.getglobalThis.fetch- Libraries that use these under the hood (axios, node-fetch, got, etc.)
