Object Creation for Multiple API Calls

Can an object be created with the help of which multiple API calls can be made? For example

  • I have two APIs to call, namely:-
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") }
});
  • Here I’m calling crops in the first and crop/details in the second.
  • I want to know if a class can be written, such that I can access them anywhere, rather than calling them multiple times every time.