0.3.0 • Published 5 years ago

@malijs/tojson v0.3.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

@malijs/tojson

Mali toJSON middleware. If the response object has a toJSON function it's executed upon payload. Only applies for UNARY and REQUEST_STREAM call types.

Example

const toJSON = require('@malijs/tojson')

function handler(ctx) {
  const obj = {
    email: 'bob@gmail.com',
    password: 'mysecret'
  }

  obj.toJSON = function() {
    return {
      email: this.email
    }
  }

  ctx.res = obj // password will not be in the payload to client
}

app.use('fn', toJSON(), handler)