title: Nested axios requests from different web services
body: <p>I have a problem (using NodeJS + Express) trying to retrieve in <strong>'users'</strong> information from 3 different requests (2 domains) and I can't get what I want. I'd like a function <strong>getAllUsers()</strong> to return something like this:</p>
  
  <pre><code>[
      {
          "username": "joe_example",
          "plays": 178,
          "friends": 7,
          "uri": "/users/joe_example"
      },
      ...snip additional users...
  ]
  </code></pre>
  
  <p>Here's my main function:</p>
  
  <pre><code>async function getAllUsers() {
      let users = await axios.get('http://localhost:8000/friends')
          .then(response =&gt; { 
              response.data["friends"].map(user =&gt; {
                  user = getUser(user.username)
              })
          })
          .catch(error =&gt; console.log(error))
      return users 
  }
  
  async function getUser(name) {
      let user = await axios.all(
          [
              axios.get('http://localhost:8000/friends/' + name),
              axios.get('http://localhost:8001/plays/' + name)
          ]).then(axios.spread((res1, res2) =&gt; {
              user["username"] = name
              user["friends"] = res1.data["friends"].length
              user["plays"] = res2.data["plays"].length
              user["uri"] = "/users/" + name
          })).catch(error =&gt; { console.log(error) })
      return user 
  }
  </code></pre>
  
  <p>Yes, it may sounds crazy...Friends service has user names and you have to call <code>/friends/&lt;username&gt;</code> in order to retrieve the amount of friends each user has, same with <code>/plays/&lt;username&gt;</code></p>
  
  <p>Any ideas or suggestions ? I've tried all I know :(</p>