New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@kumori/http-message

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kumori/http-message

HTTP server for Kumori platform

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
3
Created
Source

semantic-release

Http Message

Http server for Kumori Platform components.

Description

This library extends NodeJS HTTP server to support Kumori's channels (see Kumori's documentation for more information about channels and Kumori's service application model).

const http = require('@kumori/http-message')
let server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('okay');
})
server.listen(channel, (error) => {
    // Do something
})

This HTTP server is compatible with most of the existing http frameworks like ExpressJS.

Table of Contents

Installation

Install it as a npm package

npm install -g @kumori/http-message

Usage

Kumori Platform incorporates a communication mechanism specifically designed for elastic software and is based on channels. A channel is an object a service component can use to communicate with other components. In this document we assume you already know what a Kumori component. If that is not the case, please refere to Kumori's documentation.

Http Message package has been developed specifically for Kumori's channels. It mimmics http NodeJS server API but changes some methods to use Kumori's channels instead of ports, IPs and/or domains. Let's see it in a couple of examples.

Simple Server

This is a simple hello world server encapsulated in a Kumori's component. It is based on the example used in NodeJS documentation.

const BaseComponent = require('component');
const http = require('@kumori/http-message');

class Component extends BaseComponent {

  constructor
    (runtime
    ,role
    ,iid
    ,incnum
    ,localData
    ,resources
    ,parameters
    ,dependencies
    ,offerings
    ) {
      super(runtime, role, iid, incnum, localData, resources, parameters, dependencies, offerings);
      this.httpChannel = offerings.endpoint;
  }

  run () {
    super.run();
    const server = http.createServer();
    server.on('request', (req, res) => {
      res.statusCode = 200;
      res.setHeader('Content-Type', 'text/plain');
      res.end('Hello World\n');
    });

    server.listen(this.httpChannel);
  }
}
module.exports = Component;

Simple Client

Http Message can be also used to communicate with an http server deployed as a Kumori component.

const BaseComponent = require('component');
const http = require('@kumori/http-message');

class Component extends BaseComponent {

  constructor
    (runtime
    ,role
    ,iid
    ,incnum
    ,localData
    ,resources
    ,parameters
    ,dependencies
    ,offerings
    ) {
      super(runtime, role, iid, incnum, localData, resources, parameters, dependencies, offerings);
      this.httpChannel = offerings.endpoint;
  }

  run () {
    super.run();
    const options = {
      channel: this.httpChannel,
      method: 'POST',
      path: '/upload'
    };
    const req = http.request(options, (res) => {
      res.on('data', (chunk) => {
        doThings(chunk)
      });
      res.on('end', () => {
        doThings()
      }
    });

    req.on('error', (e) => {
      doThings(e)
    });

    req.write(dataToSend);
    req.end();
  }
}
module.exports = Component;

WARNIG: currently, setTimeout and abort method are not supported.

License

MIT © Kumori Systems

FAQs

Package last updated on 01 Oct 2018

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