@sfd-br/response-util
v0.1.1
Published
Http Utility to make the SFD Standard Response
Downloads
4
Keywords
Readme
Http Utility to make the SFD Standard Response
Install
$ npm i -S @sfd-br/response-util
Usage
const responseUtil = require('@sfd-br/response-util');
// Send a 200 response with a JSON as result
responseUtil.makeResponseSuccess(response, result);
// Send a 200 response with a Plain result number/string
responseUtil.makeResponseSuccessPlain(response, result);
// Send a 200 response with a JSON as result
responseUtil.makeResponseCreated(response, result);
// Send SFD ResponseError with any error statusCode, treated or not
responseUtil.makeResponseError(response, error);
Example
const responseUtil = require('@sfd-br/response-util');
/*
* Returns all available assets.
*/
function listAssets(req, res) {
var asset = req.swagger.params.name.value;
var blockchain = req.swagger.params.blockchain.value;
service(blockchain).listAssetsWithIssuer(asset).then(
function(result) {
responseUtil.makeResponseSuccess(res, result);
}).catch(function(error) {
responseUtil.makeResponseError(res, error);
});
}
License
SFD