api-jack
Tool to comunicate microservices
Last updated 2 months ago by ogranada .
MIT · Original npm · Tarball
$ cnpm install api-jack 
SYNC missed versions from official npm registry.

Jack

A simple comunication tool for microservices based on HTTP via REST.

How to use it


const Jack = require('jack');

p = new Jack({
  name: 'sampleServer'
});

p.addResource('content', ['id', 'url'], {
  // you can implement GET, POST, PUT, DELETE and PATCH to comunicate your microservicess passing information accross them.
  get: function*(id, url) { // you can use a generator or a simple function
    console.log('call get...');
    return {  // you should return an object with status code and response value
      status: 200,
      response: {
        id: id,
        url: url,
        sample: 'get'
      }
    };
  },
  post: function (id, url) {
    console.log('call post...', {id, url});
    return {
      status: 201,
      response: {
        id: id,
        url: url,
        sample: 'post'
      }
    };
  },
  put: function (id, url) {
    console.log('call put...', {id, url});
    return {
      status: 202,
      response: {
        id: id,
        url: url,
        sample: 'put'
      }
    };
  },
  delete: function (id, url) {
    console.log('call delete...', {id, url});
    return {
      status: 202,
      response: {
        id: id,
        url: url,
        sample: 'delete'
      }
    };
  },
  patch: function (id, url) {
    console.log('call patch...', {id, url});
    return {
      status: 202,
      response: {
        id: id,
        url: url,
        sample: 'patch'
      }
    };
  }
});

// now start your listener
p.start(function (data) {
  console.log('----> Listening at:', data.port);
});
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |