using System;
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.Net.Http;
using System.Text;

namespace WebApi.ConsumingEndpoints
{
    class Program
    {
        static void Main(string[] args)
        {
            var httpClient = new HttpClient();

            Console.WriteLine("Start Consuming");
            Console.ReadLine();

            httpClient.GetAsync( "http://localhost:8080/endpoints/episode/" )
                .ContinueWith( result =>
                                   {
                                       var response = result.Result;

                                       response.EnsureSuccessStatusCode();

                                       response.Content
                                           .ReadAsAsync<JsonArray>()
                                           .ContinueWith( readResult =>
                                                              {
                                                                  var array = readResult.Result;

                                                                  foreach ( var element in array )
                                                                  {
                                                                      Console.WriteLine(element);
                                                                  }

                                                              } );

                                   } );

            Console.ReadLine();
        }
    }
}
