Node.js Axios请求-查看响应中的所有对象

Node.js Axios请求-查看响应中的所有对象,node.js,angular,express,axios,Node.js,Angular,Express,Axios,我尝试运行多个API请求并显示来自所有API请求的数据,我尝试了几种不同的方法,但没有一种方法包含来自请求的所有数据 我得到的最接近的(包含第二个请求中的所有内容,仅包含第一个请求中的“名称”: router.get('/summoner', (req, res) => { return axios.get('https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/SUMMONERNAME', { hea

我尝试运行多个API请求并显示来自所有API请求的数据,我尝试了几种不同的方法,但没有一种方法包含来自请求的所有数据

我得到的最接近的(包含第二个请求中的所有内容,仅包含第一个请求中的“名称”:

router.get('/summoner', (req, res) => {
  return axios.get('https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/SUMMONERNAME', {
    headers: head
  })
  .then(summoner => {
    return axios.get('https://euw.api.riotgames.com/api/lol/EUW/v1.3/stats/by-summoner/SUMMONERID/summary?season=SEASON2017', {headers: head});
  })
  .then(summoner => {
    res.json(summoner.data);
  })
  .catch(function (error) {
    console.log(error);
  });
});
仅包含第一次调用的所有数据:

router.get('/summoner2', (req, res) => {

  axios.all([
    axios.get('https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/SUMMONERNAME', {headers: head}),
    axios.get('https://euw.api.riotgames.com/api/lol/EUW/v1.3/stats/by-summoner/SUMMONERID/summary?season=SEASON2017', {headers: head})
  ])
  .then(axios.spread(function(summonerResponse, statsResponse){
    res.json(summonerResponse.data);
    res.json(statsResponse.data);
  }))
});
仅包含来自第一个请求的所有数据:

router.get('/summoner3', (req, res) => {

  function getSummoner(){

    return axios.get('https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/SUMMONERNAME', {headers: head});

  }

  function getStats(){

    return axios.get('https://euw.api.riotgames.com/api/lol/EUW/v1.3/stats/by-summoner/SUMMONERID/summary?season=SEASON2017', {headers: head});

  }

  axios.all([getSummoner(), getStats()])
  .then(axios.spread(function (summoner, stats) {
    res.json(summoner.data)
    res.json(stats.data)
  }));
});

我现在正在学习,所以这里可能完全错了,但任何帮助都将不胜感激。

您只能发送一次回复。 当前您正在发送两次
res.json();res.json()
。 它不是那样工作的。您可以在nodejs控制台中看到错误日志

记住:一个请求,一个响应

您只需发送一次,如下所示


res.json([caller.data,stats.data])
您只能发送一次响应。 当前您正在发送两次
res.json();res.json()
。 它不是那样工作的。您可以在nodejs控制台中看到错误日志

记住:一个请求,一个响应

您只需发送一次,如下所示

res.json([caller.data,stats.data])