km-observer

Consumes and formats public REST API method payloads.


Install
npm install km-observer@0.1.3

Documentation

km-observer

Consumes and formats public REST API method payloads

Requirements

  • Node >=6.10.3 (to target AWS Lambda)

Install

npm install

Usage

const Observer = require('km.observer');

let observer = new Observer('http://example.com/sample.json');

observer.deploy.then(payload => console.log(payload));

Custom Output Format

// sample.json
{ "foo": "bar" }
let observer = new Observer('http://example.com/sample.json', { 'should-be-bar': 'foo' });

observer.deploy().then(payload => console.log(payload));
{ 'should-be-bar': 'bar' }

This also works recursively

// complex.json
{ "recursive": { "foo" : { "foo": "bar" } } }
let format = { 'should-be-bar': 'recursive.foo.foo' },
    observer = new Observer('http://example.com/complex.json', format);
    
observer.deploy().then(payload => console.log(payload));
{ 'should-be-bar': 'bar' }

Optionally, you can expose the raw payload with a custom output format

let format = { 'should-be-bar': 'foo', 'should-be-raw': 'raw' },
    observer = new Observer('http://example.com/sample.json', format, 'raw');
    
observer.deploy().then(payload => console.log(payload));
{ 'should-be-bar': 'bar', 'should-be-raw': { "foo": "bar" } }

Test

npm test

Dependencies

Development Dependencies