private async SystemTasks.Task <FhirResponse> ParseBinary(HttpContent content, CommandRequest request, FhirResponse fhirResponse)
        {
            var binaryResource = new Binary();

            var data = await content.ReadAsByteArrayAsync();

            if (data == null)
            {
                throw new HttpRequestException($"Request resulted in nothing for: {request.FullUrl}.");
            }

            try
            {
                binaryResource.Content     = data;
                binaryResource.ContentType = content.Headers.ContentType?.MediaType;

                fhirResponse.Resource = binaryResource;
            }
            catch (Exception ex)
            {
                throw new HttpRequestException(ex.Message, ex.InnerException);
            }

            return(fhirResponse);
        }
        private async SystemTasks.Task <FhirResponse> ParseResource(HttpContent content, CommandRequest request, FhirResponse fhirResponse)
        {
            var data = await content.ReadAsStreamAsync();

            if (data == null)
            {
                throw new HttpRequestException($"Request resulted in nothing for: {request.FullUrl}.");
            }

            using (var reader = new StreamReader(data, Encoding.UTF8))
            {
                try
                {
                    var mediaType = content.Headers.ContentType.MediaType.ToLowerInvariant();

                    var body = reader.ReadToEnd();

                    if (!string.IsNullOrEmpty(body))
                    {
                        if (mediaType.Contains("xml"))
                        {
                            var xmlParser = new FhirXmlParser();
                            fhirResponse.Resource = xmlParser.Parse <Resource>(body);
                        }
                        else
                        {
                            var jsonParser = new FhirJsonParser();
                            fhirResponse.Resource = jsonParser.Parse <Resource>(body);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new HttpRequestException(ex.Message, ex.InnerException);
                }
            }

            return(fhirResponse);
        }