Socket
Socket
Sign inDemoInstall

collar-http-transport

Package Overview
Dependencies
49
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    collar-http-transport

collar.js http transport


Version published
Maintainers
1
Install size
3.83 MB
Created

Readme

Source

collar.js-http-transport

http transport for collar.js

Usage:

Node.js

First install it with npm:

npm install collar-http-transport --save

Listen to HTTP/HTTPS requests

Require it and create an HttpServerTransport instance

const express = require('express');
const app = express();

const HttpServerTransport = require('collar-http-transport').HttpServerTransport;
const transport = new HttpServerTransport(
  app, // express app
  {   // options
    baseUrl: 'http://localhost:3333',  // base url
    url: '/double'   // route to listen
  }
)

Next, use it in the listen and resp operator

ns.listen('/double', transport)
  .map('value x 2', s => {
    let v = s.get('value');
    return s.new({
      value: v * 2
    });
  })
  .resp('send response', transport);

send request

Require it and create an HttpClientTransport instance

const HttpClientTransport = require('collar-http-transport').HttpClientTransport;
const clientTransport = new HttpServerTransport(
  {
    baseUrl: 'http://localhost:3333',  // base url
    url: '/double'   // route to send request to
  }
)

Next, use it in the req operator

ns.input('input')
  .req('request', clientTransport)
  .do('check result', s => {
     console.log(s.getResult());
  })
Browser

download the js file in build folder and include it in your webpage

<script src="js/collar-http-transport.min.v0.1.0.js"></script>

In browser, only client transport is available

send request

Create an HttpClientTransport instance

const clientTransport = new HttpClientTransport({
  baseUrl: 'http://localhost:3333',  // base url
  url: '/double'   // route to send request to
})

Next, use it in the req operator

ns.input('input')
  .req('request', clientTransport)
  .do('check result', s => {
     console.log(s.getResult());
  })

Keywords

FAQs

Last updated on 16 Dec 2016

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc