question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can I do multiple requests in a row?

See original GitHub issue

For instance:

axios.get('http://www.google.com')
    .then(function (res) {

    })
    .get('http://www.apple.com')
    .then(function (res) {

    })
    .catch(function (e) {

    })

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

326reactions
mzabriskiecommented, Jul 9, 2016

It would look something like:

axios.get('http://google.com')
  .then((res) => {
    // do something with Google res

    return axios.get('http://apple.com');
  })
  .then((res) => {
    // do something with Apple res
  })
  .catch((err) => {
    // handle err
  });

Alternatively you can send both requests simultaneously and handle responses at the same time:

axios.all([
    axios.get('http://google.com'),
    axios.get('http://apple.com')
  ])
  .then(axios.spread((googleRes, appleRes) => {
    // do something with both responses
  });
78reactions
c0d3stercommented, Apr 13, 2018

I just wanted to tack on that there’s a small syntax error on the above solution, for anyone reading through this issue trying to use axios.all. The above solution is missing a closing parenthesis on the call to .then(

axios.all([
    axios.get('http://google.com'),
    axios.get('http://apple.com')
  ])
  .then(axios.spread((googleRes, appleRes) => {
    // do something with both responses
  }));

Happy coding!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send multiple requests using axios - Storyblok
Let us start with a small task and sending one request using Axios itself. First, we import axios and define the API/URL we...
Read more >
Update Requests - Send one email for multiple rows of ...
Yes, this is possible ! One way to do this is to set up your Update Request to be a time-based workflow (see...
Read more >
Can I do multiple SQL requests as a single request
You can use JOINS to join the rows and use a where clause to specify the type you want. It would definitely be...
Read more >
Multi-Query Requests | API Connector - Mixed Analytics
To run multiple requests, list your URLs on separate lines. When you run the request, each subsequent response will be appended to the...
Read more >
How can I export multiple requests to a spreadsheet?
For this to work, every request that you're exporting needs to be exactly the same. A spreadsheet has fixed columns, so if there...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found