Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jericopulvera's avatar

Dynamically synchronous request axios

How do I make an axios synchronous request dynamically?

var array = [0,1,2];
axios.get('api/' + array[0]).then(response => {
    axios.get('api/' + array[1]).then(response => {
         axios.get('api/' + array[2]).then(response => {
            alert('done');
         });
    });
});
0 likes
1 reply
bobbybouwmann's avatar

You can do something like this

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

So your homework is to make this dynamically ;)

Documentation: https://github.com/axios/axios#example

Please or to participate in this conversation.