Refactored out repeated code in RestClient