Code Monkey home page Code Monkey logo

jm-ms's Introduction

jm-ms

MicroService lib, light and fast

Install with:

npm install jm-ms

Usage

Simple example, included as examples/simple.js:

var jm = require('jm-ms');
var app = jm.ms();

app
    .add('/hello/:name', 'get', function (opts, cb) {
        console.log('hello called. \n %s', JSON.stringify(opts, null, 2));
        cb(null, { name: opts.params.name, age: opts.data.age});
    })
    .get('/hello/jeff', {age: 10}, function (err, doc) {
        console.log('request /hello. get result: \n %s', JSON.stringify(doc, null, 2));
    })
;

This will display:

hello called.
 {
  "uri": "/hello/jeff",
  "type": "get",
  "data": {
    "age": 10
  },
  "originalUri": "/hello/jeff",
  "baseUri": "",
  "params": {
    "name": "jeff"
  }
}
request /hello. get result:
 {
  "name": "jeff",
  "age": 10
}

Http

Http example, included as examples/http.js:

jm.ms.server(app, {
    type: 'http',
    port: 3000
});

It'll add create a web server.

jm.ms.client({
    uri: 'http://localhost:3000'
}, function(err, doc){
    var client = doc;
    client.get('/hello/jeff', {age: 10}, function (err, doc) {
        logger.debug('request /hello. get result: \n %s', JSON.stringify(doc, null, 2));
    })
});

It'll add create a web client and do a request to the server.

Websocket

Websocket example, included as examples/ws.js:

jm.ms.server(app, {
    type: 'ws',
    port: 3000
});

It'll add create a websocket server.

jm.ms.client({
    uri: 'ws://localhost:3000'
}, function(err, doc){
    var client = doc;
    client.on('open', function() {
        client.get('/hello/jeff', {age: 10}, function (err, doc) {
            logger.debug('request /hello. get result: \n %s', JSON.stringify(doc, null, 2));
        })
    });
});

It'll add create a websocket client and do a request to the server.

Filter

Filter example, included as examples/filter.js:

Contributors

The original author is Jeff YU

License

MIT

Consolidation

If you want to join our cause by help maintaining something, please don't hesitate to contact either one of us.

jm-ms's People

Contributors

jammacn 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.