private async Task <RawEndpointResult> LoadWithFormRaw(Object data, Object query)
        {
            var endpointResult = new RawEndpointResult();

            endpointResult.FormData = new MultipartFormDataContent();

            try
            {
                HttpClient httpClient = await SetupRequest(query, endpointResult);

                if (data != null)
                {
                    FormContentBuilder.BuildFormContent(data, endpointResult.FormData);
                    endpointResult.Request.Content = endpointResult.FormData;
                }

                endpointResult.Response = await httpClient.SendAsync(endpointResult.Request);

                return(endpointResult);
            }
            catch (Exception)
            {
                endpointResult.Dispose(); //If there are any errors, dispose the result and rethrow
                throw;
            }
        }
        private async Task <HttpClient> SetupRequest(object query, RawEndpointResult endpointResult)
        {
            var httpClient = clientFactory.GetClient();

            endpointResult.Request = await clientFactory.GetRequestMessage();

            endpointResult.Request.Method = new HttpMethod(link.Method);
            var uriBuilder = new UriBuilder(link.Href);

            if (query != null)
            {
                uriBuilder.Query = QueryBuilder.BuildQueryString(query);
            }

            endpointResult.Request.RequestUri = uriBuilder.Uri;
            endpointResult.Request.Headers.Add("Accept", "application/json+halcyon");
            return(httpClient);
        }
        private async Task <RawEndpointResult> LoadRaw(Object data, Object query)
        {
            var endpointResult = new RawEndpointResult();

            try
            {
                HttpClient httpClient = await SetupRequest(query, endpointResult);

                if (data != null)
                {
                    endpointResult.Request.Content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
                }

                endpointResult.Response = await httpClient.SendAsync(endpointResult.Request);

                return(endpointResult);
            }
            catch (Exception)
            {
                endpointResult.Dispose(); //If there are any errors, dispose the result and rethrow
                throw;
            }
        }