Calibrate
Micro library for providing uniform json output for RESTful APIs, with error handling.
Feel free to raise an issue or contact me on twitter if you have any questions @johnbrett_. Beginners, feature requests and bug reports are welcomed.
Please star if you using this module so I know where to focus my time spent on open source work.
Usage:
const Calibrate = /*** Checks whether data is an error, calls either Calibrate.error or Calibrate.reponse**/ // Valid response structure: "statusCode": ... "data": ... "meta": ... // Error response structure: "statusCode": ... "error": ... "message": ... /*** If data is non-null and defined:* - wraps value in object with statusCode and meta properties* If null or undefined* - returns a Boom notFound error object**/Calibrate /*** If is a Boom Error object* - returns object as is* If is a non Boom Error Object* - returns a Boom badImplementaion Error Object**/Calibrate /*** **For use with Hapi.js framework (http://hapijs.com)*** Decorates the reply interface with the calibrate method**/Calibratedecorate // register as a hapijs plugin /** * If decorating your server using a Glue (https://github.com/hapijs/glue) manifest, * you can use `calibrate/decorate` as the plugin name. * Background: https://github.com/johnbrett/calibrate/issues/55 **/
Example in Hapijs:
'use strict'; const Hapi = ;const Calibrate = ;const server = port: 3000 ; async await server; // server; async await serverstart;});
License MIT @ John Brett