refactoring code to make the REST api loaded through builder function