0.0.1 • Published 7 years ago

kofi-body v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

kofi-body

npm npm npm

Body parser for kofi.js

kofi-body is a body parser for the kofijs framework. It supports url-encoded, json and text data. This does not parse multipart data, use kofi-form instead.

Installation

npm install kofi-body

Usage

var kofi = require('kofi');
var kofi_body = require('kofi-body');

//Parse data from application/x-www-form-urlencoded
kofi.use(kofi_body.encoded({ limit: 1024 * 1024 }));

//Parse data from application/json
kofi.use(kofi_body.json({ limit: 1024 * 1024 }));

//Parse data form text/plain
kofi.use(kofi_body.text({ limit: 1024 * 1024 }));

//Add your middlewares
kofi.use(function(req, res, next)
{
  //Your parsed data is in req.body

  //Do your magic
  // ...
});
//Run the server
kofi.listen(3000);

API

kofi_body.{type}(opt)

Parses the body data from the specified type. This method returns a new middleware that can be used with the kofi.use method. This method accepts an object with the following options:

  • limit: a number with the maximum request body size y bytes. Default is set to 1024.

kofi_body.encoded(opt)

Parses the body data from application/x-www-form-urlencoded.

kofi_body.json(opt)

Parses the body data from application/json.

kofi_body.text(opt)

Parses the body data from text/plain.

License

MIT LICENSE © Josemi Juanes.

0.0.1

7 years ago