Refactor client-side APIService