bj-body

1.0.2 • Public • Published

bj-body

npm install --save bj-body

1. simple usage:

examplified by test code as below:

  import {JsonFromRaw} from 'bj-body';
  var app = new koa();

  app.use(async (ctx) => {
    var body = await JsonFromRaw(ctx);
    body.should.eql({ foo: 'bar' });
    done();
  });

  request(app.listen())
  .post('/')
  .send({ foo: 'bar' })
  .end(function(){});

2. customizing usage:

  import {JsonFromStr, rawBody} from 'bj-body';
  var app = new koa();

  app.use(async (ctx) => {
    var raw = await rawBody(ctx);
    //console.log('raw body:', raw);
    raw.should.eql('{"foo":"bar"}');
    var body = await jsonFromStr(raw);
    ctx.request.body = body;
    body.should.eql({ foo: 'bar' });
    done();
  });

  request(app.listen())
  .post('/')
  .send({ foo: 'bar' })
  .end(function(){});

Package Sidebar

Install

npm i bj-body

Weekly Downloads

0

Version

1.0.2

License

MIT

Last publish

Collaborators

  • jibuji