public static async Task <IHalHttpResponseMessage> CreateAsync(HttpResponseMessage response, IHalJsonParser parser)
        {
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (parser == null)
            {
                throw new ArgumentNullException(nameof(parser));
            }

            var message = new HalHttpResponseMessage(response);

            if (message.IsHalResponse)
            {
                var content = await response.Content.ReadAsStringAsync();

                if (content.Length > 0)
                {
                    var result = parser.Parse(content);

                    message.Resource = new RootResourceObject(result);
                }
                else
                {
                    message.Resource = new RootResourceObject();
                }
            }

            return(message);
        }
Пример #2
0
        private async Task <IRootResourceObject> ParseContentAsync(HttpResponseMessage response)
        {
            var json = await response.Content.ReadAsStringAsync();

            var result = _parser.Parse(json);

            return(new RootResourceObject(result));
        }