title: How do I call two different REST api endpoints simultaneously and display the data from both on one endpoint of my app?
body: <p>I am building a simple application for my portfolio using <a href="https://developers.themoviedb.org/3/getting-started/introduction" rel="nofollow noreferrer">The Movie Database</a> api. In my GET /movie route, I want to get and display the data about the movie, and the names and photos of the cast members, however the data for the movie and the data for the cast members belong two separate endpoints of the api, and I am at a complete loss as to how to access both response data sets under a single endpoint in my app.  </p>
  
  <p>I cannot call axios.get() on both endpoints under the /movie route because I will get a "Headers already sent" error, and I have tried to write a function that uses axios.get for 1 endpoint that returns the response and gets called in my GET /movie route, but that causes the entire GET route to return undefined.</p>
  
  <p>Here is my current code for my /movie route that is incorrect, but closely conveys what I am trying to accomplish</p>
  
  <pre><code>const express = require('express');
  const router = express.Router();
  const axios = require('axios');
  const api_key = require('../config/keys').api_key;
  const imgURL = "http://image.tmdb.org/t/p/";
  const dateFormat = require('../config/dateFormat');
  
  getActors = movie_id =&gt; {
      axios.get(`https://api.themoviedb.org/3/movie/${movie_id}/credits?api_key=${api_key}&amp;language=en-US`)
          .then(res =&gt; { 
              return res.data;
           }).catch(err =&gt; console.log(err.message));
  }
  
  router.get('/:id', (req, res) =&gt; {
      const id = req.params.id
      axios.get(`https://api.themoviedb.org/3/movie/${id}?api_key=${api_key}&amp;language=en-US`)
          .then(res =&gt; {
              const movieData = res.data;
              const actors = getActors(id); //calling above function here, but returns undefined and hangs the application
              res.render('movie', {movieInfo: movieData, imgURL: imgURL, releaseDate: dateFormat(movieData.release_date), actors: actors})
          })
          .catch(err =&gt; console.log(err.status_message))
  });
  
  module.exports = router;
  
  </code></pre>
  
  <p>any help is greatly appreciated.</p>