Skip to content

Instantly share code, notes, and snippets.

@DeVoresyah
Created June 20, 2020 07:40
Show Gist options
  • Save DeVoresyah/72fe28df0300e953ae0c7ccee4545735 to your computer and use it in GitHub Desktop.
Save DeVoresyah/72fe28df0300e953ae0c7ccee4545735 to your computer and use it in GitHub Desktop.
Standar API Response
const HttpStatus = require('http-status-codes')
module.exports = function api(data, code) {
const { req, res } = this
const response = {
response: {
status: code,
message: HttpStatus.getStatusText(code),
url: `${req.protocol}://${req.hostname}${req.originalUrl}`
},
data
}
return res.status(code).json(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment