3.0.3 • Published 9 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.pathmethod 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.pathshould be used instead ofopts.url(the host and port are added from the resource config)- No
opts.methoddefaults toGET - the
opts.pathstring can use templates using keys on from theopts.parametersobject formis 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, andprefixfrom the resource config - Supports templating with
{KEY}againstopts.parameters
- Prefixed with the
opts- If no
parameters,body,qs, orheadersparam 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, andprefixfrom the resource config - Supports templating with
{KEY}againstopts.parameters
- Prefixed with the
opts- If no
parameters,body,qs, orheadersparam 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, andprefixfrom the resource config - Supports templating with
{KEY}againstopts.parameters
- Prefixed with the
opts- If no
parameters,body,qs, orheadersparam 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, andprefixfrom the resource config - Supports templating with
{KEY}againstopts.parameters
- Prefixed with the
opts- If no
parameters,body,qs, orheadersparam 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 /statuson the service - The service will perform a
GET /statuson all of its dependent services - All ternary dependencies will be ignored to prevent a loop back
- Calling
Statusdirectly on micron-client will get the status of all registered services - Takes arguments
optsopts.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
optspatameter of each request should follow the request module structure- rather than
url, apathparameter is expected - the path parameter should be used to map functionality of the service client being written
- rather than
- the
pathparameter should template properties ofopts.pathOptsmatching{OPT_NAME}
Authors
3.0.3
9 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
10 years ago
1.1.3
10 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