restify-res-plugin
v0.1.5
Published
Add methods 'ok' and 'error' to the res object
Downloads
3
Readme
Restify Response Plugin
res.ok('Data')
{ isSuccess: true, data: "Data" }
res.error('Message')
{ isSuccess: false, error: "Message" }
Installation
npm install restify-res-plugin
Example
const restify = require('restify')
const restifyResPlugin = require('restify-res-plugin')
const server = restify.createServer()
server.use(restifyResPlugin())
server.get('/', (req, res) => {
res.ok('Data')
})
server.get('/with-meta-data', (req, res) => {
res.ok('Data', { page: 1 })
})
server.get('/error', (req, res) => {
res.error('Error message')
})
server.get('/error-with-status', (req, res) => {
res.error(400, 'Error message')
})
Options
- defaultErrorStatus (default 200)
Success / Faile
also you can use res.success and res.fail