Socket
Book a DemoInstallSign in
Socket

co-respond

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-respond

Respond to HTTP requests with co streams

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

co-respond

Respond to http requests with co streams.

build status

Example

Respond with a stream that yields a string three times.

var http = require('http');
var co = require('co');
var respond = require('co-respond');
var wait = require('co-wait');

var server = http.createServer(function(req, res){
  co(function*(){
    try {
      yield respond(res, thrice('  hi!\n'));
    } catch (err) {
      res.statusCode = 500;
      res.end('  ' + err.message + '\n');
    }
  })();
});

function thrice(str){
  var i = 0;
  return function*(end){
    if (end || i++ > 2) return;
    yield wait(1000);
    return str;
  }
}

server.listen(8007);
console.log('curl http://localhost:8007/');

Installation

$ npm install co-respond

API

yield respond(res, stream)

Pipes the co stream stream into res and yields when done.

Throws if stream or res emit an error.

License

MIT

FAQs

Package last updated on 16 Aug 2014

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