collar-http-transport
v0.1.2
Published
collar.js http transport
Downloads
3
Readme
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());
})