Created
October 26, 2023 14:26
-
-
Save pdaug/58a91596fd731bbbd560e03e837ae238 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SCRIPT TO MAKE MULTIPLE REQUESTS WITH AXIOS | |
import axios from "axios" | |
const servers = { | |
anything: "https://httpbin.org/anything", | |
ip: "https://httpbin.org/ip", | |
useragent: "https://httpbin.org/user-agent", | |
headers: "https://httpbin.org/headers", | |
}; | |
const urlServers = Object.values(servers); | |
const requests = urlServers.map(function(url) { | |
const method = "GET"; | |
const email = "[email protected]"; | |
const password = "12345678"; | |
const data = { email, password, }; | |
const axiosParams = { method, url, data, }; | |
return axios(axiosParams); | |
}); | |
const results = axios.all(requests); | |
results | |
.then(axios.spread(function(...responses) { | |
for (const response of responses) { | |
console.log(response.data); | |
} | |
})) | |
.catch(function(error) { | |
console.error(error); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment