3.0.3 • Published 8 years ago
micron-client v3.0.3
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: 'test@tester.com',
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
- 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
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
, 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
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
, 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
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
, 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
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
, 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
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
, 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}
Authors
3.0.3
8 years ago
3.0.2
9 years ago
3.0.1
9 years ago
2.1.1
9 years ago
3.0.0
9 years ago
2.1.0
9 years ago
2.0.0
9 years ago
1.1.4
9 years ago
1.1.3
9 years ago
1.1.2
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.6
10 years ago
1.0.5
10 years ago
1.0.4
10 years ago
1.0.3
10 years ago
1.0.2
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago