malijs / tojson

Mali middleware that automatically calls toJSON on response

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@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)

About

Mali middleware that automatically calls toJSON on response

License:Apache License 2.0


Languages

Language:JavaScript 100.0%