【问题标题】:Centralize data from multiple APIs集中来自多个 API 的数据
【发布时间】: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


    【解决方案1】:

    这条线看起来很奇怪:

    res.json[exchangeone, exchangetwo, exchangethree, exchangequattro]
    

    如果你在服务器上使用 express.js - .json - 是一个函数,你可以试试这个:

    let data = [exchangeone, exchangetwo, exchangethree, exchangequattro]
    res.json(data)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      相关资源
      最近更新 更多