0.3.0 • Published 5 years ago

@malijs/param v0.3.0

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

@malijs/param

Mali request param middleware

npm version build status

API

@malijs/param

Mali param middleware. If the request object has the specified property of specified type the middleware function is executed. Only applies for UNARY and RESPONSE_STREAM call types.

ParamTypeDescription
paramNameStringThe name of the request object property
optionsOptions
options.typeStringOptional type of the param specified by paramName within the request. Has to be one of possible values as returned by typeof.
options.truthyBooleanoptional check for truthiness on the param value within the request. Default: false
fnfunctionThe middleware function to execute

Example

const param = require('@malijs/param')

async function appendDocType (id, ctx, next) {
  ctx.req.id = 'user::'.concat(id)
  await next()
}

app.use(param('id', { type'string', truthy: true }, appendDocType))

License

Apache-2.0