Socket
Book a DemoInstallSign in
Socket

makine

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

makine

Basis for an HTTP event-driven machine, typically useful for CI/CD triggers.

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
6
500%
Maintainers
1
Weekly downloads
 
Created
Source

makine

Basis for a reactive HTTP event-driven machine, typically useful for CI/CD triggers.

This allows for a quick implementation of logic in HTTP-based flows involving Web Hooks, REST APIs and scheduled monitoring.

Installation

npm install makine --save

Usage

As a new engine

const { extract on, reply, request, response, serve } = require('makine')();

serve()(
    on('GET', '/ok')(
        reply(response.empty())
    ),
    on('GET', '/hello')(
        reply(response.body({ message: "ciao" })
    )  
)

In an existing Express application

const app = ...
const { extract on, reply, request, response, serve } = require('makine')(app);

serve()(
    on('GET', '/ok')(
        reply(response.empty())
    ),
    on('GET', '/hello')(
        reply(response.body({ message: "ciao" })
    )  
)

Use another port

serve(7777)(
    ...
)

Request Pipeline

Makine request handling with .on() is actually an RxJS pipeline with helpers.

  on('POST', '/test')(
    reply(req => of(req).pipe(
      extract.body('path'), // extract the path from the original request
      map(path => 
        ({ uri: `http://localhost:3000/${path}` })), // prepare the new request
      request.perform(), // perform the new request
      extract.body('greeting'), // extracts the message from the response
      map(greeting => ({ message: `${greeting} you!` })), // prepare our response body
      request.onErrorMap(404, // in case the new request failed with 404 
        res => of({ message: `We had problem with ${res.uri}` })),
      flatMap(response.body())), // prepare the response with the prepared body

Keywords

event-driven

FAQs

Package last updated on 28 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.