Skip to content

cainus/onBodyMiddleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#onBodyMiddleware Build Status Coverage Status NPM version

This is a simple connect middleware for getting an http request's body as a buffer or string because I got tired of doing it manually.

This middleware adds an onBody function to the req and calls back when done.

The onBody function takes a callback in the form

function(err, body){ ...

...where err is an error that may have occurred and body is the entire body of the request.

onBodyMiddleware is useful for any scenario where the streaming interface is unnecessary (basically anytime you need the entire body before you can do any processing).

###Setup:

var onBodyMiddleware = require('onBodyMiddleware');
connectApp.use(onBodyMiddleware);

###Use:

  function(req, res){
    req.onBody(function(err, body){
      if (err){
        res.end(JSON.stringify(err));
      } else {
        console.log(body);
        res.end("nice body!");
      }
    });
  }

About

a connect middleware for getting an http request's body as a buffer or string

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published