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 = ; let client = ; let result = clientuserService;
Middleware
- Allows sockets to stay open for server duration
let micron = ;let config = ; // koa let koa = ;let koaApp = ; koaApp;koaApp // express  express = ;let expressApp = ; expressApp;expressApp
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
- The only major change is that the url and host are pulled from the config. The
- All other operations are simply wrappers of this function
- Important notes
opts.path
should be used instead ofopts.url
(the host and port are added from the resource config)- No
opts.method
defaults toGET
- the
opts.path
string can use templates using keys on from theopts.parameters
object form
is aliased asbody
- All requests default to type JSON
clientsomeMicronService;
.create/.post
- Wraps .request
- Takes arguments
(path, opts)
path
- Prefixed with the
host
,port
, andprefix
from the resource config - Supports templating with
{KEY}
againstopts.parameters
- Prefixed with the
opts
- If no
parameters
,body
,qs
, orheaders
param exists, the object will be set as the body/form
- If no
clientsomeMicronService; // OR clientsomeMicronService;
.read/.get
- Wraps .request
- Takes arguments
(path, opts)
path
- Prefixed with the
host
,port
, andprefix
from the resource config - Supports templating with
{KEY}
againstopts.parameters
- Prefixed with the
opts
- If no
parameters
,body
,qs
, orheaders
param exists, the object will be set as the body/form
- If no
clientsomeMicronService; // OR clientsomeMicronService;
.update/.put
- Wraps .request
- Takes arguments
(path, opts)
path
- Prefixed with the
host
,port
, andprefix
from the resource config - Supports templating with
{KEY}
againstopts.parameters
- Prefixed with the
opts
- If no
parameters
,body
,qs
, orheaders
param exists, the object will be set as the body/form
- If no
clientsomeMicronService; // OR clientsomeMicronService;
.destroy/.delete
- Wraps .request
- Takes arguments
(path, opts)
path
- Prefixed with the
host
,port
, andprefix
from the resource config - Supports templating with
{KEY}
againstopts.parameters
- Prefixed with the
opts
- If no
parameters
,body
,qs
, orheaders
param exists, the object will be set as the body/form
- If no
clientsomeMicronService; // OR clientsomeMicronService;
.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 clientsomeMicronServicestatus; // all status's clientstatus;
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
, apath
parameter is expected - the path parameter should be used to map functionality of the service client being written
- rather than
- the
path
parameter should template properties ofopts.pathOpts
matching{OPT_NAME}