refactoring the fetch data method to handle multiple rest api calls.