I'm attempting to call this end point: https://blockchain.info/rawtx/$tx_hash
in the following manner using the request-response module:
api.get('/transaction/:hash', (req, res) => {
const hash = (req.params.hash);
let uri = 'https://blockchain.info/rawtx/' + hash;
rp(uri).then(function (txInfo) {
let result = JSON.parse(txInfo);
}
Is there a cleaner way of calling an end point as opposed to just concatenating the argument?
I think this is clean enough. Your other option is
.concat()
but that's just slower. If you prefer templating and are in an es6 supported environment then you can do leturi = 'https://blockchain.info/rawtx/${hash}'
; as suggested in the above comment. But like I said, I think the way you are doing it now is fit for purpose.