2017-08-31 35 views
0

我試圖把這種終點:https://blockchain.info/rawtx/$tx_hash以下列方式使用請求響應模塊:使用參數在節點中獲取請求的最佳做法是什麼?

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); 
} 

有呼叫終點,而不是僅僅串聯的說法更清潔的方式嗎?

+0

可以使用字符串模板:'let uri = \'https://blockchain.info/rawtx/$ {req.params.hash} \''' – tymeJV

回答

1

我覺得這很乾淨。您的其他選項是.concat(),但這只是較慢。如果你更喜歡模板,並且處於es6支持的環境中,那麼你可以讓uri = 'https://blockchain.info/rawtx/${hash}';正如上述評論所建議的那樣。但就像我說的,我認爲你現在這樣做的方式適合目的。

相關問題