mikrop
Rapid microservice development library based on Restify.
Last updated 7 hours ago by muratersin .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mikrop 
SYNC missed versions from official npm registry.

Mikrop

Mikrop is a rapid api development library based on restify.

npm version Build Status

Mikrop contain common methods and packages for required every micro service.

Usage

installing:

  npm i --save mikrop

Configuration

const mikrop = require('mikrop');

// default config
const config = {
  apiDir: `${process.cwd()}/api`,
  requiredVariables: [],
  useRequestLogger: true,
  useAuditLogger: true,
  useMongo: false,
  dateParser: 60,
  server: ServerOptions,
  throttle: ThrottleOptions,
  bodyParser: BodyParserOptions,
  queryParser: QueryParserOptions,
  cpuUsageThrottle: CpuUsageThrottleOptions,
};

mikrop.run(config); // mikrop listening at http://[::]:3000

apiDir: string

Absolute path of where contain your api handlers and config files.

requiredVariables: [string]

Array of required env variable for working your service.

useRequestLogger: boolean

If you want to see request logs on terminal, it's must be true.

useAuditLogger: boolean

Detailed error log for monitoring.

useMongo: boolean

If it's true and you have a valid env called MONGO_URI, service connect to database when starting.

Route And Handler Definition

Folder structure is most important thing for Mikrop.

Your folder structure must be as shown below:

my-microservice
  |-- api -> This folder path can change with configuration object.
    |--user
      |--index.js    -> Contain route handler methods.
      |--config.json -> Contain path and methods.
  |-- lib
  |-- index.js
  ...etc

iapi/user/ndex.js:

module.exports.getUser = (req, res, next) => {
  res.send('Get user');
};
module.exports.updateUser = (req, res, next) => {
  res.send('Update user');
};
module.exports.formValidation = (req, res, next) => {
  res.send('Form validation');
};

api/user/config.json:

{
  "name": "User api",
  "description": "Sample user api description",
  "routes": {
    "/user": {
      "get": {
        "handlers": ["getUser"],
        "public": true
      }
    },
    "/user/:id": {
      "put": {
        "handlers": ["formValidation", "updateUser"]
      }
    }
  }
}

index.js:

const mikrop = require('mikrop');

mikrop.run(); // mikrop listening at http://[::]:3000

mikrop wants some env variable for running.

  NAME=Service Name
  PORT=3000
  URL=localhost
  NODE_ENV=development

You can add more required env variable for specific services.

Configuration:

const mikrop = require('mikrop');

const options = {
  requiredVariables: [
    'MY_REQUIRED_ENV_VARIABLE',
  ],
},

mikrop.run(options); // mikrop listening at http://[::]:3000

Current Tags

  • 0.1.1                                ...           latest (7 hours ago)

14 Versions

  • 0.1.1                                ...           7 hours ago
  • 0.1.0                                ...           7 hours ago
  • 0.0.12                                ...           a month ago
  • 0.0.11                                ...           a month ago
  • 0.0.10                                ...           a month ago
  • 0.0.9                                ...           a month ago
  • 0.0.8                                ...           a month ago
  • 0.0.7                                ...           a month ago
  • 0.0.6                                ...           a month ago
  • 0.0.5                                ...           a month ago
  • 0.0.4                                ...           a month ago
  • 0.0.3                                ...           a month ago
  • 0.0.1                                ...           a month ago
  • 1.0.0                                ...           2 months ago
Maintainers (1)
Downloads
Today 22
This Week 22
This Month 22
Last Day 0
Last Week 0
Last Month 157
Dependencies (13)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |