api-recorder
HTTP JSON API Recorder. Record API responses and replay them offline.
Last updated 2 years ago by flochtililoch .
ISC · Original npm · Tarball · package.json
$ cnpm install api-recorder 
SYNC missed versions from official npm registry.

HTTP JSON API Recorder

Record API responses and replay them offline. Useful for UI testing setups.

Runs a proxy server that acts in two modes:

  • recording mode: stores every responses of target API to specified directory.
  • replay mode: respond to API requests using previously recorded responses.

Installation

$ npm install api-recorder -g

Configuration

{
  "port": 3000,
  "directory": "~/offline_data",
  "target": "http://my.api.local:8080",
  "fingerprint": [
    "method",
    "url",
    "query",
    "body",
    {
      "headers": [
        "user-agent",
        "accept-language",
        "host"
      ]
    }
  ]
}

port Integer

Port used by the proxy.

directory String

Directory to write to / read from API responses.

target String

Real server hosting the API to record.

fingerprint Array

List of keys from the request object to use to "fingerprint" the request. Can be specifed as an object when reading request object properties (for example headers).

Usage

CLI

Record API responses

$ api-recorder -c=/path/to/config.json

Replay API responses (offline mode)

$ api-recorder -c=/path/to/config.json --offline

Replay API responses that are already recorded, record others

$ api-recorder -c=/path/to/config.json --offline --autofix

Node API

const apiRecorder = require('api-recorder');

// Initialize and start HTTP service
const service = apiRecorder({
  config: '/path/to/config.json',
  directory: '/path/to/directory',
  offline: false // or true
});

// Some code that pulls data from the service

service.close(); // Close HTTP service

TODO

  • [x] allow request fingerprinting customization
  • [ ] allow responses delaying by configuration
  • [ ] tests
  • [ ] support non-JSON APIs

Current Tags

  • 0.0.12                                ...           latest (2 years ago)

12 Versions

  • 0.0.12                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.10                                ...           2 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.8                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (8)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |