koa-protobuf-parser

0.1.1 • Public • Published

koa protobuf parser

Middlware that parses protocol buffers from request body.

Installation

npm install koa-protobuf-parser

Usage

/* users.proto file
 
message User {
  string email = 1;
  string name = 2;
}
 
*/
 
const router = require('koa-router')();
const parser = require('koa-protobuf-parser');
const Protobuf = require('protobufjs');
 
const builder = Protobuf.loadProtoFile('users.proto');
const User = builder.build('User');
 
router.post('test', parser(User), function *() {
  const { message } = this;
  console.log(message);
  /*
  {
    name: 'Lucas',
    email: 'sunsi.lucas@gmail.com',
  }
  */
});

License

MIT

Package Sidebar

Install

npm i koa-protobuf-parser

Weekly Downloads

0

Version

0.1.1

License

ISC

Last publish

Collaborators

  • lsunsi