Refactor HTTP request into client