Skip to content

Instantly share code, notes, and snippets.

@pdaug
Created October 26, 2023 14:26
Show Gist options
  • Save pdaug/58a91596fd731bbbd560e03e837ae238 to your computer and use it in GitHub Desktop.
Save pdaug/58a91596fd731bbbd560e03e837ae238 to your computer and use it in GitHub Desktop.
// 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