Example #1
0
        /// <summary>
        /// Performs an HTTP PATCH against a specified URI.
        /// </summary>
        /// <typeparam name="TRequest">The request body type</typeparam>
        /// <typeparam name="TResponse">The response body type</typeparam>
        /// <param name="uri">The URI</param>
        /// <param name="content">The request body content</param>
        /// <param name="operationName">The operation name</param>
        /// <param name="headers">Headers to add to the request</param>
        /// <returns>The response body content</returns>
        public async Task <TResponse> PatchAsync <TRequest, TResponse>(Uri uri, TRequest content, string operationName, NameValueCollection headers = null)
        {
            WebApiClientRequest <TRequest>   request  = this.CreateRequest(new HttpMethod("PATCH"), uri, content, operationName, headers);
            WebApiClientResponse <TResponse> response = await this.SendAsync <TResponse>(request).ConfigureAwait(false);

            return(response.Content);
        }
Example #2
0
        /// <summary>
        /// Performs an HTTP DELETE against a specified URI.
        /// </summary>
        /// <typeparam name="T">The request and response body type</typeparam>
        /// <param name="uri">The URI</param>
        /// <param name="operationName">The Operation Name</param>
        /// <param name="headers">Headers to add to the request</param>
        /// <returns>The response body content</returns>
        public async Task <T> DeleteAsync <T>(Uri uri, string operationName, NameValueCollection headers = null)
        {
            WebApiClientRequest      request  = this.CreateRequest(HttpMethod.Delete, uri, operationName, headers);
            WebApiClientResponse <T> response = await this.SendAsync <T>(request).ConfigureAwait(false);

            return(response.Content);
        }
Example #3
0
        /// <summary>
        /// Handle successful response
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="httpResponseMessage"></param>
        /// <param name="mediaType"></param>
        /// <param name="formatter"></param>
        /// <returns></returns>
        private static async Task <WebApiClientResponse <T> > HandleResponseAsync <T>(HttpResponseMessage httpResponseMessage, string mediaType, MediaTypeFormatter formatter = null)
        {
            // TODO mayuro: workaround RDFE bug that the response's header is fixed 'application/xml'
            httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
            T content = default(T);

            if (typeof(T) == typeof(string))
            {
                string response = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                content = (T)Convert.ChangeType(response, typeof(T));
            }
            else
            {
                if (formatter != null)
                {
                    List <MediaTypeFormatter> formatters = new List <MediaTypeFormatter>();
                    formatters.Add(formatter);

                    content = await httpResponseMessage.Content.ReadAsAsync <T>(formatters).ConfigureAwait(false);
                }
                else
                {
                    content = await httpResponseMessage.Content.ReadAsAsync <T>().ConfigureAwait(false);
                }
            }

            var result = new WebApiClientResponse <T>
            {
                HttpStatusCode = httpResponseMessage.StatusCode,
                Content        = content
            };

            result.Headers.Add(httpResponseMessage.Headers.ToNameValueCollection());
            return(result);
        }