GithubHelp home page GithubHelp logo

pjb3 / api-recorder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flochtililoch/api-recorder

0.0 1.0 0.0 49 KB

HTTP JSON API Recorder. Record API responses and replay them offline.

JavaScript 100.00%

api-recorder's Introduction

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

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

api-recorder's People

Contributors

flochtililoch avatar pjb3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.