Can an object be created with the help of which multiple API calls can be made? For example
export const getCropDetails = (cropDetails, token) => API.get(`/crop?name=${cropDetails}`, {
headers: { "Content-Type": "application/json", "authorization": localStorage.getItem("token") }
});
export const getCropDetails = (cropDetails, token) => API.get(`/crop/details?name=${cropDetails}`, {
headers: { "Content-Type": "application/json", "authorization": localStorage.getItem("token") }
});
Are you looking for something like this ?
class MultipleAPI {
constructor() {}
async makeMultipleAPICalls() {
const getCropDetailsOne = (cropDetails, token) =>
API.get(`/crop?name=${cropDetails}`, {
headers: {
"Content-Type": "application/json",
authorization: localStorage.getItem("token")
}
});
const getCropDetailsTwo = (cropDetails, token) =>
API.get(`/crop/details?name=${cropDetails}`, {
headers: {
"Content-Type": "application/json",
authorization: localStorage.getItem("token")
}
});
const results = await Promise.all([
getCropDetailsOne,
getCropDetailsTwo
]);
return results;
}
}
const h = new MultipleAPI();
console.log(h.makeMultipleAPICalls().then(res => console.log("res", res)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With