separated the API handling to method