refactor out api call as func