【发布时间】:2022-07-19 20:48:48
【问题描述】:
我想知道如何将多个 api 的数据集中在一个 api 上
我想在地址 /coingeckotest 处获得四个 res.data 的结果
目前我可以在终端中看到我想要的结果,但是在 /coingeckotest 页面上我返回了“null”值
提前感谢您的回答
这是我的脚本
async function datauniswap() {
let datauniswap = await axios
.get('https://api.coingecko.com/api/v3/exchanges/uniswap/tickers')
.then((res) => {
console.log(res.data)
})
return datauniswap
}
async function datasushiswap() {
let datasushiswap = await axios
.get('https://api.coingecko.com/api/v3/exchanges/sushiswap/tickers')
.then((res) => {
console.log(res.data)
})
return datasushiswap
}
async function datacurvefinance() {
let datacurvefinance = await axios
.get('https://api.coingecko.com/api/v3/exchanges/curve/tickers')
.then((res) => {
console.log(res.data)
})
return datacurvefinance
}
async function dataquickswap() {
let dataquickswap = await axios
.get('https://api.coingecko.com/api/v3/exchanges/quickswap/tickers')
.then((res) => {
console.log(res.data)
})
return dataquickswap
}
server.get('/coingeckotest', async (req, res) => {
exchangeone = await datauniswap();
exchangetwo = await datasushiswap();
exchangethree = await datacurvefinance();
exchangequattro = await dataquickswap();
cacheTime = Date.now();
res.json[exchangeone, exchangetwo, exchangethree, exchangequattro]
})
【问题讨论】:
标签: javascript node.js api express