extracts common logic for sending request to server