Created
June 20, 2020 07:40
-
-
Save DeVoresyah/72fe28df0300e953ae0c7ccee4545735 to your computer and use it in GitHub Desktop.
Standar API Response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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