npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

micron-client

v3.0.3

Published

Client for interaction between micron-based microservices

Downloads

7

Readme

Micron Client

npm Dependencies Join the chat at https://gitter.im/johnhof/micron-client

Client for interaction between micron based microservices.

The goal of micron is to simplify construction and communication between micro-services, regardless of the communication method. The client and service currently support communication over REST/HTTP, ØMQ, and others.

$ npm install --save micron-client

Key

Usage

Spot

  • should be used in a shared fashion to prevent constant socket connection overhead
let micron = require('micron-client');

let client = micron({
  userService : {
    micron: 'zeromq', // specify zeromq as the communication method
    // OR
    micron: 'http', // specify HTTP as the communication method

    prefix: 'v1', // prefix all request url's
    host: '127.0.0.1', /// host of the service
    port: 8001 // port of the service
  }
});

let result = yield client.userService.post('user/create', {ß
  email: '[email protected]',
  password: 'Tester@1'
});

Middleware

  • Allows sockets to stay open for server duration
let micron = require('micron-client');
let config = require('./services.json');

// koa

let koa = require('koa');
let koaApp = koa();

koaApp.use(micron.middleware.koa());
koaApp.listen(8000)


// express

 express = require('express');
let expressApp = express();

expressApp.use(micron.middleware.express());
expressApp.listen(8000)

Operations

.request

  • Follows the object structure of the request module's base request builder
    • The only major change is that the url and host are pulled from the config. The opts.path method should be used instead
  • All other operations are simply wrappers of this function
  • Important notes
    • opts.path should be used instead of opts.url (the host and port are added from the resource config)
    • No opts.method defaults to GET
    • the opts.path string can use templates using keys on from the opts.parameters object
    • form is aliased as body
    • All requests default to type JSON
yield client.someMicronService.request({
  method: 'post',
  path: '/foo/{foo_id}',
  parameters: {
    foo_id: 'FooId12345'
  },
  body: {
    foo_property: 'bar'
  },
  qs: {
    foo_query: 'bar'
  }
});

.create/.post

  • Wraps .request
  • Takes arguments (path, opts)
    • path
      • Prefixed with the host, port, and prefix from the resource config
      • Supports templating with {KEY} against opts.parameters
    • opts
      • If no parameters, body, qs, or headers param exists, the object will be set as the body/form
yield client.someMicronService.post('/foo/FooId12345', {
  foo_property: 'bar'
});

// OR

yield client.someMicronService.post('/foo/{foo_id}', {
  parameters: {
    foo_id: 'FooId12345'
  },
  body: {
    foo_property: 'bar'
  }
});

.read/.get

  • Wraps .request
  • Takes arguments (path, opts)
    • path
      • Prefixed with the host, port, and prefix from the resource config
      • Supports templating with {KEY} against opts.parameters
    • opts
      • If no parameters, body, qs, or headers param exists, the object will be set as the body/form
yield client.someMicronService.get('/foo/FooId12345?foo_query=bar');

// OR

yield client.someMicronService.get('/foo/{foo_id}', {
  parameters: {
    foo_id: 'FooId12345'
  },
  qs: {
    foo_query: 'bar'
  }
});

.update/.put

  • Wraps .request
  • Takes arguments (path, opts)
    • path
      • Prefixed with the host, port, and prefix from the resource config
      • Supports templating with {KEY} against opts.parameters
    • opts
      • If no parameters, body, qs, or headers param exists, the object will be set as the body/form
yield client.someMicronService.put('/foo/FooId12345', {
  foo_property: 'bar'
});

// OR

yield client.someMicronService.put('/foo/{foo_id}', {
  parameters: {
    foo_id: 'FooId12345'
  },
  body: {
    foo_property: 'bar'
  }
});

.destroy/.delete

  • Wraps .request
  • Takes arguments (path, opts)
    • path
      • Prefixed with the host, port, and prefix from the resource config
      • Supports templating with {KEY} against opts.parameters
    • opts
      • If no parameters, body, qs, or headers param exists, the object will be set as the body/form
yield client.someMicronService.delete('/foo/FooId12345', {
  foo_property: 'bar'
});

// OR

yield client.someMicronService.delete('/foo/{foo_id}', {
  parameters: {
    foo_id: 'FooId12345'
  },
  body: {
    foo_property: 'bar'
  }
});

.status

  • Performs a GET /status on the service
  • The service will perform a GET /status on all of its dependent services
  • All ternary dependencies will be ignored to prevent a loop back
  • Calling Status directly on micron-client will get the status of all registered services
  • Takes arguments [opts]
    • opts.timeout
      • timeout in milliseconds for each status request
// singular status
yield client.someMicronService.status();

// all status's
yield client.status();

Contributing

Add new clients to the ./lib/clients directory as an independant file. Each client should support all operations above

Requirements

  • the opts patameter of each request should follow the request module structure
    • rather than url, a path parameter is expected
    • the path parameter should be used to map functionality of the service client being written
  • the path parameter should template properties of opts.pathOpts matching{OPT_NAME}

Authors