Giter VIP home page Giter VIP logo

toki's Introduction

Toki

A configuration based orchestration rules engine that's protocol agnostic.

npm version Build Status Known Vulnerabilities NSP Status

Lead Maintainer: Cesar Hernandez

Introduction

Toki is an orchestration layer for microservice based architectures. It is both HTTP server agnostic, and downstream protocol agnostic. It's configuration based and allows you to bring your own logger.

Key Features

  • Configuration based using version-able JSON files. Easy to write, easy to deploy.

  • Bring your own HTTP framework so you can use Express, Koa, Hapi or whatever else floats your boat.

  • Protocol Agnostic so you can speak whatever your microservices are speaking. HTTP, RabbitMQ, etc.

  • Supports any standard logger so you can plug it into your existing log setup.

Getting Started

To allow Toki to be used by any http framework, Toki uses small modules we call 'bridges'. The bridge appropriate for your webserver framework is where you should start:

Don't see a bridge you need? Please feel free to contribute one. Bridges are easy to write, we promise!

You can also peek at our reference implementation, which provides a fully setup and ready to roll Toki implementation out of the box that's heavily commented and explained.

API

See the API Reference.

We also have guides on how to build your very own:

Toki configuration

Toki action handler

Examples

Check out the Examples.

Contributing

We love community and contributions! Please check out our guidelines before making any PRs.

Setting up for development

Getting yourself setup and bootstrapped is easy. Use the following commands after you clone down.

npm install
npm test

toki's People

Contributors

cesarhq avatar dhinklexo avatar westyler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

toki's Issues

Workflow State

Hi,
I would like to know if Toki saves the workflow state under the hood.
Does it use a message broker(pub-sub) or is it pure request response?

Allow for optional "options" to be passed for an action config

Context

  • Each action configuration should allow for an optional untyped options object to be passed through. Because we are making action plugins first class citizens and exporting the functionality of http actions to be a function of toki-method-http, the options needs to be passed with the routes and action verbs associated to that action along with even customizable templated payloads.
  • Documentation needs to be specific that this optional untyped options object is not validated by toki core and the responsibility of that is on the onus of the plugin itself.

Update configuration naming in tests and responder

For consistency, we should use the naming standards established by toki-method-http.

Changes needed:

  • clientResponse renamed to clientResponseConfiguration
  • createConfiguration renamed to inputConfiguration
  • (if used) assembleConfiguration renamed to outputConfiguration

Documentation : config action.type

Context

  • The action.type attribute is not clear that this value is what we use to require in toki-method-* plugins. All of the examples have action.type names that do not align with our toki-method-* plugin signature. Do we want to consider doing something webpack does which is optionally, you can plug in a name that does not prepend with toki-method and we will try to prepend the signature if one does not match? If not, we should be clear in our examples what to expect via a naming convention.

Implement "failure" action in the ruleset

What are you trying to achieve or the steps to reproduce ?

I would like to do something like:

"actions": [ /*list of toki actions to take. nothing different here.*/ ],
"failure": [{
    "name": "RabbitCatch",
    "type": "toki-method-rabbit",
    "createConfiguration": {
         "event": "toki.request_failed",
        /*the rest of the event mapping*/
    }
}]

Add built-in response sender method

What are you trying to achieve or the steps to reproduce ?

Since Toki delegates the responsibility for sending HTTP responses to action methods in all cases except for "uncaught" errors (500 Server Error), there should be an action "type" that indicates that an HTTP response needs to be sent. Methods like toki-method-proxy and toki-method-http handle the response delegation, but there are use cases (below) in which the action needed is nothing more than a simple HTTP response.

What result did you expect ?

The contrived "failure" ruleset should result in a rabbit event being emitted, then a mapped response being sent back to the client.

"failure": [
    {
        "name": "rabbit action",
        "type": "toki-method-rabbit",
        "rabbitConfiguration": { /*BunnyBus configs*/ },
        "createConfiguration": {
            "event": "toki.request-failed",
            "message": {
                "processed": false,
                "errors": "{{=it.errors}}"
            }
        }
    },
    {
        "name": "error response",
        "type": "responder",
        "clientResponse": {
            "statusCode": "{{=it.errors.designatedStatusCode}}",
            "payload": "{{=it.errors.optionalPayload}}"
        }
    }
]

What result did you observe ?

Since the built in HTTP responder does not exist, the request hangs open when the "failure" ruleset is executed.

Requirements

  • An action (whether in "actions" or "failure" rulesets) with the type "responder" should utilize the build in responder method instead of trying to require('responder').
  • The clientResponse should support toki-templater templated payloads.
  • The clientResponse config is required and has the following Joi schema:
    const responderConfig = Joi.object().keys({
        statusCode: Joi.alternatives().try(Joi.string, Joi.number()).required(),
        payload: Joi.alternatives().try(Joi.string(), Joi.object()).optional()
    }).required();
  • The HTTP response should be sent with the configured statusCode and, if present, payload.
  • An error in responder should result in the default error handler sending back a 500 Server Error response.

Support "local" methods

We should allow for the use of toki methods that are not published to npm/private repositories. This will allow for business logic written on a service to be used inside of Toki route configurations.

There is some security research needed, but the initial implementation being discussed involves adding something like the below here;

        const localMethods = requiredir(path.join(process.cwd(), './methods');

        //require handler to be called as per configuration type
        let handler;

        if (localMethods[action.type]) {
            handler = localMethods[action.type];
        }
        else if (action.type === 'responder') {
            handler = require('./responder');
        }
        else {
            handler = require(action.type);
        }

Documentation : context object specification

Context

We need additional documentation around the context object to help green to us engineers understand what is being offered exactly for the method actions to use.

  • context.request
    • what is the exact contract we are offering with decorations on top of the node request object
  • context.reply
    • what does this action do exactly?
  • How does the actions configuration section map on the context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.